search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Home Backend Development PHP Empire CMS website management system-secondary development manual Introduction to writing extended SQL programs for Imperial CMS

Introduction to writing extended SQL programs for Imperial CMS

Collection 47
Read 29179
update time 2016-09-11
Basic example:
Note: The following examples are based on placing PHP files in the system root directory.

Example 1: Connect to MYSQL program. (a.php)
##<?php#Example 2: Program to operate MYSQL data. (b.php)
require('e/class/connect.php'); //Introduce the database configuration file and Public function file
require('e/class/db_sql.php'); //Introduce database operation file
$link=db_connect(); //Connect to MYSQL
$empire=new mysqlquery(); //Declare the database operation class

db_close();                                                                                                                                                                                                               




##<?phprequire('e/class/connect.php'); //Introduce the database configuration file and Public function filerequire('e/class/db_sql.php'); //Introduce database operation file
$link=db_connect(); //Connect to MYSQL$empire=new mysqlquery(); //Declare the database operation class$empire->query("update {$dbtbpre}ecms_news set onclick=onclick 1"); //Add 1 to the number of clicks in the news table

db_close();                                                                                                   ‐                                       ’ s ’ s ’ s ’ s ’ ‐ ‐ ‐ ‐ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ out to MYSQLBlow        out out out out out out out out out out out out out out's's to ’ s ’ s ’ ‐ ‐ ‐‐‐‐‐‐‐​ ​ ​ ​ ​ ​ ​ ​

Example 3: Program to read MYSQL data. (c.php)
##<?php
Hot AI Tools
Undress AI Tool
Undress AI Tool

Undress images for free

AI Clothes Remover
AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress
Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT
ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT
Stock Market GPT

AI powered investment research for smarter decisions

Popular tool
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)

require('e/class/connect.php'); //Introduce the database configuration file and Public function file
require('e/class/db_sql.php'); //Introduce database operation file
$link=db_connect(); //Connect to MYSQL
$empire=new mysqlquery(); //Declare the database operation class

$sql=$empire->query("select * from {$dbtbpre}ecms_news order by newstime limit 10"); //Query the latest 10 records of the news table
while($r=$empire->fetch($sql)) //Loop to get query records
{
echo"Title:".$r['title']."<br>" ;
}

db_close();                                                                                     ‐           ‐                                                                 ‐         ‐                                     ’ ’s ’ ’ s ’ s ’ s ’ s ’ s ’ ‐ ‐ ‐ ‐ ‐ ​ ​ ​ ​ ​ ​ ​​ ​



Description of commonly used functions in the database operation class in the /e/class/db_sql.php file:
1. Execute SQL functions :
$empire->query("SQL statement");
$empire->query1("SQL statement");

Description:
Execution is returned successfully true, returns false if the execution is unsuccessful;
The difference between the two is: an error in query() directly interrupts program execution, and an error in query1() does not interrupt program execution.

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

2. Loop to read database records Function:
$empire->fetch($sql)

Description:
$sql is the result returned by query execution SQL.

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

3. Read a single database Record function: (No loop)
$empire->fetch1("SQL statement")

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

4. Statistics SQL query record number function:
$empire->num("SQL statement")
$empire->num1($sql)

Explanation:
The difference between the two is: num() directly Write a SQL statement, and $sql in num1() is the result returned by query executing SQL.

Usage example:
$num=$empire->num("select id from {$dbtbpre}ecms_news");
echo"The news table has a total of ".$num." news ";

5. Statistical SQL query record number function 2: (a more efficient function compared to num)
$empire->gettotal("Statistical SQL statement");

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:
$num=$empire->gettotal("select count(*) as total from {$dbtbpre}ecms_news");
echo"The news table has a total of".$ num." news";

6. Get the auto-increment ID value function just inserted into the table:
$empire->lastid()

Use Example:
$empire->query("insert into {$dbtbpre}ecms_news(title) values('title')");
$lastid=$empire->lastid();
echo "The ID of the information just inserted is: ".$lastid;

7. Move the SQL query result record pointer:
$empire->seek($sql,$pit )

Explanation:
$sql is the result returned by query executing SQL, and $pit is the offset number of the pointer.

Usage example:
$sql=$empire->query("select * from {$dbtbpre}ecms_news");
$empire->seek($sql,2);

8. Release SQL query result function: (generally not required)
$empire->free($sql)

Instructions:
$sql is the result returned by query executing SQL.

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