1、执行SQL语句
$db->query("INSERT INTO `{$DT_PRE}table` (`xxx`) VALUES ('yyy')");
$db->query("UPDATe `{$DT_PRE}table` SET `xxx`='yyy' WHERe `zzz`=1");
$db->query("DELETE FROM `{$DT_PRE}table` WHERe `zzz`=1");
2、读取单条信息
$A = $db->get_one("SELECt * FROM `{$DT_PRE}table` WHERe `xxx`='yyy'");
print_r($A);
print_r($A);
3、计算总数
$A = $db->get_one("SELECt COUNT(*) AS num FROM `{$DT_PRE}table` WHERe `xxx`='yyy'");
echo $A['num'];
echo $A['num'];
4、读取多条信息
$A = array();
$result = $db->query("SELECt * FROM `{$DT_PRE}table` WHERe `xxx`='yyy' ORDER BY `zzz` DESC LIMIT 0,10");
while($r = $db->fetch_array($result)) {
$A[] = $r;
}
print_r($A);
$result = $db->query("SELECt * FROM `{$DT_PRE}table` WHERe `xxx`='yyy' ORDER BY `zzz` DESC LIMIT 0,10");
while($r = $db->fetch_array($result)) {
$A[] = $r;
}
print_r($A);
5、分页
$A = array();
$r = $db->get_one("SELECt COUNT(*) AS num FROM `{$DT_PRE}table` WHERe `xxx`='yyy'");
$pages = pages($r['num'], $page, $pagesize);
$result = $db->query("SELECt * FROM `{$DT_PRE}table` WHERe `xxx`='yyy' ORDER BY `zzz` DESC LIMIT $offset,$pagesize");
while($r = $db->fetch_array($result)) {
$A[] = $r;
}
print_r($A); echo $pages;
系统的表前缀可以使用变量$DT_PRE(一般在语句中使用)或者$db->pre(一般在函数中使用)。$r = $db->get_one("SELECt COUNT(*) AS num FROM `{$DT_PRE}table` WHERe `xxx`='yyy'");
$pages = pages($r['num'], $page, $pagesize);
$result = $db->query("SELECt * FROM `{$DT_PRE}table` WHERe `xxx`='yyy' ORDER BY `zzz` DESC LIMIT $offset,$pagesize");
while($r = $db->fetch_array($result)) {
$A[] = $r;
}
print_r($A); echo $pages;
如果在函数中使用数据库操作,需要先进行global $db;