


Summary of examples of calling database classes in PHP files to execute SQL statements under Imperial CMS
Example 1: Example of connecting to MYSQL database. (a.php)
The code is as follows:
<?php require('e/class/connect.php'); //引入数据库配置文件和公共函数文件 require('e/class/db_sql.php'); //引入数据库操作文件 $link=db_connect(); //连接MYSQL $empire=new mysqlquery(); //声明数据库操作类</p> <p>db_close(); //关闭MYSQL链接 $empire=null; //注消操作类变量 ?>
Example 2: Update data example. (b.php)
The code is as follows:
<?php require('e/class/connect.php'); //引入数据库配置文件和公共函数文件 require('e/class/db_sql.php'); //引入数据库操作文件 $link=db_connect(); //连接MYSQL $empire=new mysqlquery(); //声明数据库操作类</p> <p>$empire->query("update {$dbtbpre}ecms_news set onclick=onclick+1"); //给新闻表的点击数加1</p> <p>db_close(); //关闭MYSQL链接 $empire=null; //注消操作类变量 ?>
Recommended to study "Empirecms Tutorial"
Example 3: Example of querying MYSQL data. (c.php)
The code is as follows:
<?php require('e/class/connect.php'); //引入数据库配置文件和公共函数文件 require('e/class/db_sql.php'); //引入数据库操作文件 $link=db_connect(); //连接MYSQL $empire=new mysqlquery(); //声明数据库操作类</p> <p>$sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime limit 10"); //查询新闻表最新10条记录 while($r=$empire->fetch($sql)) //循环获取查询记录 { echo"标题:".$r['title']." "; }</p> <p>db_close(); //关闭MYSQL链接 $empire=null; //注消操作类变量 ?>
/e/class/db_sql.php file Commonly used function descriptions for database operation classes:
1. Execute SQL functions :
The code is as follows:
$empire->query("SQL语句"); $empire->query1("SQL语句");
Explanation:
Returns true if the execution is successful, false if the execution is unsuccessful;
The difference between the two is: query() interrupts directly when an error occurs Program execution, query1() error does not interrupt program execution.
Usage example:
The code is as follows:
$sql=$empire->query("select * from {$dbtbpre}ecms_news");
2. Loop reading database record function:
The code is as follows:
$empire->fetch($sql)
Description:
$sql is the result returned by query executing SQL.
Usage example:
The code is as follows:
$sql=$empire->query("select * from {$dbtbpre}ecms_news"); while($r=$empire->fetch($sql)) { echo"标题:".$r['title']." "; }
3. Read a single database record function: (not looping)
The code is as follows:
$empire->fetch1("SQL语句")
Usage example:
The code is as follows:
$r=$empire->fetch1("select * from {$dbtbpre}ecms_news where id=1"); echo"标题:".$r['title'];
4. Statistics SQL query record number function:
The code is as follows:
$empire->num("SQL语句") $empire->num1($sql)
Explanation:
The difference between the two is: num() writes SQL statements directly, while $sql in num1() is the result returned by query executing SQL.
Usage example:
The code is as follows:
$num=$empire->num("select id from {$dbtbpre}ecms_news"); echo"新闻表共有 ".$num." 条新闻";
5. Statistical SQL query record number function 2: (a more efficient function compared to num)
The code is as follows:
$empire->gettotal("统计SQL语句");
Explanation:
The difference between gettotal() and num() is: gettotal() uses SQL’s own count(*) function for statistics, while num() uses PHP’s own Function, gettotal() is more efficient.
The statistics in gettotal() must be as total, such as: "count(*) as total".
Usage example:
The code is as follows:
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_news"); echo"新闻表共有 ".$num." 条新闻";
6. Get the auto-increment ID value function just inserted into the table:
The code is as follows:
$empire->lastid()
Usage example:
The code is as follows:
$empire->query("insert into {$dbtbpre}ecms_news(title) values('标题')"); $lastid=$empire->lastid(); echo"刚插入的信息ID为:".$lastid;
7. Move the SQL query result record pointer:
The code is as follows:
$empire->seek($sql,$pit)
Description:
$sql is the result returned by query executing SQL, and $pit is the offset number of the pointer.
Usage example:
The code is as follows:
$sql=$empire->query("select * from {$dbtbpre}ecms_news"); $empire->seek($sql,2);
8. Release the SQL query result function: (Generally no need to use)
The code is as follows:
$empire->free($sql)
Description:
$sql is the result returned by query executing SQL.
Usage example:
The code is as follows:
$sql=$empire->query("select * from {$dbtbpre}ecms_news"); $empire->free($sql);
Navigation query example:
The code is as follows:
<DIV class=news_dh style="color:#000000"></p> <p><!--主栏目导航,此模板中直接指定为classid=69,即法律法规栏目--> [e:loop={"select classid,classname,classpath from [!db.pre!]enewsclass where classid='69' and showclass=0 order by myorder ",0,24,0}] <span><a href="<?=$public_r[newsurl]?><?=$bqr[classpath]?>" ><?=$bqr[classname]?></a></span> <SPAN><IMG src="[!--news.url--]skin/tx/zixun/images/index_line_nav.gif"></SPAN> [/e:loop]</p> <p> </p> <p><!--子栏目导航--> [e:loop={"select classid,classname,classpath from [!db.pre!]enewsclass where bclassid='69' and showclass=0 order by myorder ",0,24,0}] <? $lanmuclass= "lanmu"; //echo $bqr[classid] ; //echo "cur:".$GLOBALS[navclassid]; if ( $bqr[classid]==$GLOBALS[navclassid]) { //echo "-"; $lanmuclass ="curlanmu"; } ?></p> <p><span class="<?=$lanmuclass?>"><a href="<?=$public_r[newsurl]?><?=$bqr[classpath]?>" > <?=$bqr[classname]?></a></span> <SPAN><IMG src="[!--news.url--]skin/tx/zixun/images/index_line_nav.gif"></SPAN></p> <p>[/e:loop]</p> <p> <!--新闻导航结束--> </DIV>
The above is the detailed content of Summary of examples of calling database classes in PHP files to execute SQL statements under Imperial CMS. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The Empire CMS sitemap can be found by accessing the config.inc.php file and checking the dositemap settings. If set to "on", sitemap is enabled. The sitemap path is located in the sitemapurl setting and can be accessed via a browser or downloaded via FTP.

The mobile settings of Empire CMS are located in the "Mobile Template" of the "Template Management" module. The specific steps include: enabling the template, selecting the application channel, editing the template content, and saving the settings.

The ideal location for the Empire CMS template file is /e/template/default/skin/default/. Secondly, it can also be placed in /e/data/skins/ and /e/skin/. You need to pay attention to maintaining the folder structure and setting file permissions. and regular backups.

The Imperial CMS database configuration file is located in the website root directory e/config/db.inc.php. It contains the following configuration information: $dbhost: database server address $dbuser: database user name $dbpass: database password $dbname: database name $dbport :Database port $dbcharset: Database character set

Empire CMS template download location: Official template download: https://www.phome.net/template/ Third-party template website: https://www.dedecms.com/diy/https://www.0978.com.cn /https://www.jiaocheng.com/Installation method: Download template Unzip template Upload template Select template

The automatic publishing interface of Empire CMS is located at /e/api/web/postinfo.php. The usage steps are as follows: visit /e/api/web/postinfo.php address and use HTTP POST to submit the article title, column ID, category ID, author and article The content and other data interfaces will return a response in JSON format, which contains the publishing results and article ID.

Yes, Empire CMS is a free and open source content management system (CMS). It is a lightweight CMS that is feature-rich and easy to use. Empire CMS is licensed under the GNU General Public License (GPL), which means it is free to download, install and use. For commercial use, it offers a paid version that offers additional features and support such as ad management, online payments, and premium technical support.

The imperial cms Baidu active push plug-in is located in the root directory /e/api/baidu/push.php. The specific configuration steps are as follows: 1. Upload the plug-in file to the specified path. 2. Configure the "Baidu Active Push" option in the Imperial CMS background, including push address, API Key and push interval. 3. Get Baidu push information: Push address: https://data.zz.baidu.com/urls?site=YOUR_SITE&token=YOUR_API_KEY, API Key: log in to Baidu search resource platform to obtain. 4. Update the API Key regularly and set a reasonable push interval.
