Empire CMS encapsulates a SQL, and the file location is e/class/db_sql.php; using the class library of the program itself can bring convenience and efficiency to our development, and at the same time reduce the number of additional files.
First, make the preparations:
<?php /*引用文件*/ include("../../class/connect.php"); include("../../class/db_sql.php"); /*建立数据库链接 与 实例化类*/ $link=db_connect(); $empire=new mysqlquery(); /*中间的这个位置用于我们测试代码*/ /*关闭数据库连接 与 释放类*/ db_close(); $empire=null; ?>
<?php include("../../class/connect.php"); include("../../class/db_sql.php"); $link=db_connect(); $empire=new mysqlquery(); function hr(){ echo ' <hr /-->'; } $sql=$empire->query("select id,title from {$dbtbpre}ecms_news"); var_dump($sql); hr(); //如语句执行成功则返回true $sql=$empire->query("UPDATE {$dbtbpre}ecms_news set title='标题' where id=1"); var_dump($sql); hr(); //如语句执行失败则终止执行并返回错误语句 下面的语句用了不存在的字段 $sql=$empire->query("UPDATE {$dbtbpre}ecms_news set titlesss='标题' where id=1"); var_dump($sql); hr(); db_close(); $empire=null; ?>
The source text about the query object is as follows: In the ninth line of e/class/db_sql.php; the PHP manual for die() explains that "the die() function outputs a message and exits the current script"; so the third var_dump() and hr() under the test statement exited without executing;
function query($query) { $this->sql=mysql_query($query) or die(mysql_error().''.str_replace($GLOBALS['dbtbpre'],'***_',$query)); return $this->sql; }
The object query1 is the same as mysql_query(), and the longer Chinese characters have been deleted to save space.
<?php include("../../class/connect.php"); include("../../class/db_sql.php"); $link=db_connect(); $empire=new mysqlquery(); function hr(){ echo ' <hr /-->'; } $sql=$empire->query1("select id,title from {$dbtbpre}ecms_news"); var_dump($sql); hr(); //如语句执行成功true $sql=$empire->query1("UPDATE {$dbtbpre}ecms_news set title='测试更新标题' where id=1"); var_dump($sql); hr(); //如语句执行失败则返回FLASE $sql=$empire->query1("UPDATE {$dbtbpre}ecms_news set titlesss='测试更新标题' where id=1"); var_dump($sql); hr(); db_close(); $empire=null; ?>