Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summarize the example of how to call database class to execute SQL statement in PHP file under Imperial CMS.

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail about summarizing how to call database classes to execute SQL statements in PHP files under Imperial CMS. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Example 1: example of connecting to a MYSQL database. (a.php)

The code is as follows:

Example 2: update data example. (b.php)

The code is as follows:

Recommended to learn the Imperial cms course

Example 3: an example of querying MYSQL data. (c.php)

The code is as follows:

Description of functions commonly used in database operation classes in / e/class/db_sql.php file:

1. Execute the SQL function:

The code is as follows:

$empire- > query ("SQL statement"); $empire- > query1 ("SQL statement")

Description:

True is returned for successful execution, and false for unsuccessful execution.

The difference between the two is that the query () error directly interrupts the program execution, while the query1 () error does not interrupt the program execution.

Examples of use:

The code is as follows:

$sql=$empire- > query ("select * from {$dbtbpre} ecms_news")

2. Loop read database record function:

The code is as follows:

$empire- > fetch ($sql)

Description:

Sql executes the results returned by SQL for query.

Examples of use:

The code is as follows:

$sql=$empire- > query ("select * from {$dbtbpre} ecms_news"); while ($ringing empires-> fetch ($sql)) {echo "title:". $r ['title']. ";}

3. Read a single database record function: (no loop)

The code is as follows:

$empire- > fetch2 ("SQL statement")

Examples of use:

The code is as follows:

Fetch2-> fetch2 ("select * from {$dbtbpre} ecms_news where id=1"); echo "title:". $r ['title']

4. Statistics SQL query record function:

The code is as follows:

$empire- > num ("SQL statement") $empire- > num1 ($sql)

Description:

The difference between the two is that num () writes the SQL statement directly, while the $sql in num1 () executes the result returned by SQL for query.

Examples of use:

The code is as follows:

$num=$empire- > num ("select id from {$dbtbpre} ecms_news"); echo "News list". $num. "News"

5. Statistics of SQL query record count function 2: (a more efficient function than num)

The code is as follows:

$empire- > gettotal ("Statistical SQL statement")

Description:

The difference between gettotal () and num () is that 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".

Examples of use:

The code is as follows:

$num=$empire- > gettotal ("select count (*) as total from {$dbtbpre} ecms_news"); echo "Newslist". $num. "News"

6. Get the self-increasing ID value function that has just been inserted into the table:

The code is as follows:

$empire- > lastid ()

Examples of use:

The code is as follows:

$empire- > query ("insert into {$dbtbpre} ecms_news (title) values ('title')"); $lastid=$empire- > lastid (); echo "the message ID just inserted is:". $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 of the pointer.

Examples of use:

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, it is not required)

The code is as follows:

$empire- > free ($sql)

Description:

Sql executes the results returned by SQL for query.

Examples of use:

The code is as follows:

$sql=$empire- > query ("select * from {$dbtbpre} ecms_news"); $empire- > free ($sql)

Example of navigation query:

The code is as follows:

[ePolloop = {"select classid,classname,classpath from [! db.pre!] enewsclass where classid='69' and showclass=0 order by myorder", 0meme24pl 0}]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report