class db extends PDO{
function open($modul)
{
return $this->query("select * from `$modul` ORDER by `id` ASC");
}
function open_pr($modul,$time)
{
return $this->query("select * from `$modul` where `time` > '$time' ORDER by `id` ASC");
}
function add($modul,$add)
{
return $this->exec("insert into `$modul` (`name`,`time`,`msg`) values($add)");
}
function edit($modul,$edit,$where='')
{
return $this->exec("update `$modul` set $edit $where");
}
function del($modul,$d)
{
return $this->exec("delete from `$modul` where `id`='$d'");
}
}
$db = new db("mysql:host=$DB_HOST;dbname=$DB_BASE", $DB_USER, $DB_PASS);
$db->query('set charset utf8');
$db->query('SET names utf8');
$db->query('set character_set_client="utf8"');
$db->query('set character_set_connection="utf8"');
$db->query('set character_set_result="utf8"');
class book{
function down()
{
global $db;
$res = $db->open("book");
$_SESSION['book']['time']=date("Y-m-d H:i:s");
header('Content-type: application/json');
die(json_encode($res->fetchAll()));
}
function down1()
{
global $db;
$pr_msg=$_SESSION['book']['time'];
$res = $db->open_pr("book",$pr_msg);
$_SESSION['book']['time']=date("Y-m-d H:i:s");
header('Content-type: application/json');
die(json_encode($res->fetchAll()));
}
function add($name,$msg)
{
global $db;
if($msg!="" and $name!="")
{
$time=date("Y-m-d H:i:s");
$db->add("book","'$name','$time','$msg'");
}
}
function del($d)
{
global $db;
if($d!='')
{
$db->del("book",$d);
}
}
}
$book=new book();
if($_GET['act']=='add')$book->add($_POST['name'],$_POST['msg']);
if($_GET['act']=='down')$book->down();
if($_GET['act']=='down1')$book->down1();
if($_GET['act']=='del')$book->del($_POST['d']);
?>
Изменил: Михаил (17.04.2014 / 07:47)