Home > php教程 > php手册 > destoon二次开发常用数据库操作

destoon二次开发常用数据库操作

WBOY
Release: 2016-06-06 20:21:12
Original
1301 people have browsed it

这篇文章主要介绍了destoon二次开发常用数据库操作,需要的朋友可以参考下

destoon在初始化系统后系统会自动连接数据库,,并将数据库操作对象保存在$db。对于数据库操作方法请参考include/db_mysql.class.php函数原型,下面对常用数据库操作举例说明。

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 = 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);

3、读取单条信息

$A = $db->get_one("SELECT * FROM `{$DT_PRE}table` WHERE `xxx`='yyy'"); print_r($A);

4、计算总数

$A = $db->get_one("SELECT COUNT(*) AS num FROM `{$DT_PRE}table` WHERE `xxx`='yyy'"); echo $A['num'];

系统的表前缀可以使用变量$DT_PRE(一般在语句中使用)或者$db->pre(一般在函数中使用)。
如果在函数中使用数据库操作,需要先进行global $db;

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template