Table of Contents
第一个测试的对象:query
第二个测试的对象:query1
Home php教程 php手册 如何使用帝国CMS自带的数据库类

如何使用帝国CMS自带的数据库类

Jun 13, 2016 am 09:38 AM
Secondary development Empire cms

帝国CMS封装了一个SQL,文件位置是e/class/db_sql.php;使用程序本身的类库可以给我们的开发带来便利和效率,同时可以减少增设文件数量等。

首先,做下准备工作:

  1. 在e目录下建立测试目录,例如我建立的是e/trylife/td-test/
  2. 在1中目录下建立个PHP文件,例如我建立的是e/trylife/td/test-db_sql.php
  3. 文件中写入代码如下:
<?php  
/*引用文件*/  
include("../../class/connect.php");  
include("../../class/db_sql.php");  
  
/*建立数据库链接 与 实例化类*/  
$link=db_connect();  
$empire=new mysqlquery();  
  
	/*中间的这个位置用于我们测试代码*/  
  
/*关闭数据库连接 与 释放类*/  
db_close();  
$empire=null;  
?>  
Copy after login

第一个测试的对象:query

  1. query()执行的是mysql_query()
  2. 返回值同样遵循PHP手册中对mysql_query()的解释,不过执行失败的情况下是和mysq_query不一样地
  3. 测试代码如下(去除了篇幅比较大的注释):
<?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;  
?>
Copy after login

关于query这个对象的源文如下:在e/class/db_sql.php第九行;die()查看PHP手册解释为"die() 函数输出一条消息,并退出当前脚本";所以第三条测试语句下的var_dump() 及其 hr(),都没有执行就退出了;

function query($query)  
{  
    $this->sql=mysql_query($query) or die(mysql_error().''.str_replace($GLOBALS['dbtbpre'],'***_',$query));  
    return $this->sql;  
}  
Copy after login

第二个测试的对象:query1

对象query1则和mysql_query()一样了,为节省版面长点的汉字都删了。

<?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;  
?>  
Copy after login
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Where is the imperial cms website map? Where is the imperial cms website map? Apr 17, 2024 am 10:48 AM

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.

Where are the settings for the mobile version of Empire CMS? Where are the settings for the mobile version of Empire CMS? Apr 17, 2024 pm 12:12 PM

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.

Where can I put the empire cms template file for easy use? Where can I put the empire cms template file for easy use? Apr 17, 2024 am 07:22 AM

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.

Where to find the empire cms database configuration file Where to find the empire cms database configuration file Apr 17, 2024 am 06:42 AM

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

Where is the imperial cms resource network template? Where is the imperial cms resource network template? Apr 17, 2024 am 10:00 AM

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

Everyone can become an AI developer! Robin Li brings three major AI development tools Everyone can become an AI developer! Robin Li brings three major AI development tools Apr 18, 2024 pm 03:40 PM

Emerging as the brightest star in the technology field in early 2023, it demonstrates the huge potential of Kai AI technology to transform the economy and society. After more than a year of technological breakthroughs and market verification, entering 2024, the huge value of large models has been recognized by mainstream countries, and mainstream technology companies have made plans. Countries such as the United States and China are in the future of leading the development of the large model industry. Among domestic technology companies, Baidu was the first to release Wenxin's large model and has achieved extraordinary results. At the Create2024 Baidu AI Developer Conference held today, Robin Li, founder, chairman and CEO of Baidu, revealed in his keynote speech that the number of Wenxin Yiyan users exceeded 200 million, and the Wenxin Big Model has become China's leading and most widely used model. Extensive AI base models. At the same time, Robin Li

Where is the automatic publishing interface of Empire CMS? Where is the automatic publishing interface of Empire CMS? Apr 17, 2024 am 09:03 AM

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.

Is empire cms free? Is empire cms free? Apr 17, 2024 am 11:24 AM

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.

See all articles