Home Backend Development PHP Tutorial Mysql database Mysql database operation class under PHP is modified from discuz

Mysql database Mysql database operation class under PHP is modified from discuz

Jul 29, 2016 am 08:43 AM
mysql database

复制代码 代码如下:


/* --------------------------------
System:PT book - PT小说小偷
Code: 杰少Pakey
----------------------------------- */
$pt_mysql = new dbQuery;
/**
* mysql query class
*
*/
class dbQuery {
/**
* Total number of queries
*
* @var int
*/
var $querynum = 0;
/**
* connection handle
*
* @var object
*/
var $link;
/**
* Constructor
*
* @param string $dbhost host name
* @param string $dbuser user
* @param string $dbpw password
* @param string $dbname database name
* @param int $pconnect whether to persist the connection
*/
function connect($dbhost, $dbuser, $dbpw, $dbname = '', $pconnect = 0) {
if($pconnect) {
if(!$this->link = @mysql_pconnect($dbhost, $dbuser, $dbpw)) {
$this->halt('Can not connect to MySQL server');
}
} else {
if(!$this->link = @mysql_connect($dbhost, $dbuser, $dbpw)) {
$this->halt('Can not connect to MySQL server');
}
}
if($this->version() > '4.1') {
global $dbcharset;
if($dbcharset) {
mysql_query("SET character_set_c character_set_results=$dbcharset, character_set_client=binary", $this->link);
mysql_query("set names 'GBK'");
}
if($this->version() > '5.0.1') {
mysql_query("SET sql_mode=''", $this->link);
mysql_query("set names 'GBK'");
}
}
if($dbname) {
mysql_select_db($dbname, $this->link);
}
}
/**
* Select database
*
* @param string $dbname
* @return
*/
function select_db($dbname) {
return mysql_select_db($dbname, $this->link);
}
/**
* Get a record from the result set
*
* @param object $query
* @param int $result_type
* @return array
*/
function fetch_array($query, $result_type = MYSQL_ASSOC) {
return mysql_fetch_array($query, $result_type);
}
/**
* 查询SQL
*
* @param string $sql
* @param string $type
* @return object
*/
function query($sql, $type = '') {
$func = $type == 'UNBUFFERED' && @function_exists('mysql_unbuffered_query') ?
'mysql_unbuffered_query' : 'mysql_query';
if(!($query = $func($sql, $this->link)) && $type != 'SILENT') {
$this->halt('MySQL Query Error', $sql);
}
$this->querynum++;
return $query;
}
/**
* Get the number of affected items
*
* @return int
*/
function affected_rows() {
return mysql_affected_rows($this->link);
}
/**
* Return error message
*
* @return array
*/
function error() {
return (($this->link) ? mysql_error($this->link) : mysql_error());
}
/**
* Return error code
*
* @return int
*/
function errno() {
return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());
}
/**
* Return query results
*
* @param object $query
* @param string $row
* @return mixed
*/
function result($query, $row) {
$query = @mysql_result($query, $row);
return $query;
}
/**
* Number of results
*
* @param object $query
* @return int
*/
function num_rows($query) {
$query = mysql_num_rows($query);
return $query;
}
/**
* Get the total number of fields
*
* @param object $query
* @return int
*/
function num_fields($query) {
return mysql_num_fields($query);
}
/**
* Release the result set
*
* @param object $query
* @return bool
*/
function free_result($query) {
return mysql_free_result($query);
}
/**
* Return auto-increment ID
*
* @return int
*/
function insert_id() {
return ($id = mysql_insert_id($this->link)) >= 0 ? $id : $this->result($this->query("SELECT last_insert_id()"), 0);
}
/**
* Get a row from the result set as an enumeration array
*
* @param object $query
* @return array
*/
function fetch_row($query) {
$query = mysql_fetch_row($query);
return $query;
}
/**
* Get column information from the result set and return it as an object
*
* @param object $query
* @return object
*/
function fetch_fields($query) {
return mysql_fetch_field($query);
}
/**
* Return mysql version
*
* @return string
*/
function version() {
return mysql_get_server_info($this->link);
}
/**
* Close connection
*
* @return bool
*/
function close() {
return mysql_close($this->link);
}
/**
* Output error message
*
* @param string $message
* @param string $sql
*/
function halt($message = '', $sql = '') {
echo $message . ' ' . $sql;
exit;
}
}
?>

The above introduces the Mysql database. The mysql database operation class under PHP is modified from discuz, including the content of the Mysql database. I hope it will be helpful to friends who are interested in PHP tutorials.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
PHP development practice: Use PHPMailer to send emails to users in the MySQL database PHP development practice: Use PHPMailer to send emails to users in the MySQL database Aug 05, 2023 pm 06:21 PM

PHP development practice: Use PHPMailer to send emails to users in the MySQL database Introduction: In the construction of the modern Internet, email is an important communication tool. Whether it is user registration, password reset, or order confirmation in e-commerce, sending emails is an essential function. This article will introduce how to use PHPMailer to send emails and save the email information to the user information table in the MySQL database. 1. Install the PHPMailer library PHPMailer is

Go language and MySQL database: How to separate hot and cold data? Go language and MySQL database: How to separate hot and cold data? Jun 18, 2023 am 08:26 AM

As the amount of data continues to increase, database performance has become an increasingly important issue. Hot and cold data separation processing is an effective solution that can separate hot data and cold data, thereby improving system performance and efficiency. This article will introduce how to use Go language and MySQL database to separate hot and cold data. 1. What is hot and cold data separation processing? Hot and cold data separation processing is a way of classifying hot data and cold data. Hot data refers to data with high access frequency and high performance requirements. Cold data

How to use MySQL database for time series analysis? How to use MySQL database for time series analysis? Jul 12, 2023 am 08:39 AM

How to use MySQL database for time series analysis? Time series data refers to a collection of data arranged in time order, which has temporal continuity and correlation. Time series analysis is an important data analysis method that can be used to predict future trends, discover cyclical changes, detect outliers, etc. In this article, we will introduce how to use a MySQL database for time series analysis, along with code examples. Create a data table First, we need to create a data table to store time series data. Suppose we want to analyze the number

How to use MySQL database for image processing? How to use MySQL database for image processing? Jul 14, 2023 pm 12:21 PM

How to use MySQL database for image processing? MySQL is a powerful relational database management system. In addition to storing and managing data, it can also be used for image processing. This article will introduce how to use a MySQL database for image processing and provide some code examples. Before you begin, make sure you have installed a MySQL database and are familiar with basic SQL statements. Create a database table First, create a new database table to store the image data. The structure of the table can be as follows

To what extent can I develop MySQL database skills to be successfully employed? To what extent can I develop MySQL database skills to be successfully employed? Sep 12, 2023 pm 06:42 PM

To what extent can I develop MySQL database skills to be successfully employed? With the rapid development of the information age, database management systems have become an indispensable and important component in all walks of life. As a commonly used relational database management system, MySQL has a wide range of application fields and employment opportunities. So, to what extent do MySQL database skills need to be developed to be successfully employed? First of all, mastering the basic principles and basic knowledge of MySQL is the most basic requirement. MySQL is an open source relational database management

How to perform incremental data backup of MySQL database using Go language How to perform incremental data backup of MySQL database using Go language Jun 17, 2023 pm 02:28 PM

As the amount of data increases, database backup becomes more and more important. For the MySQL database, we can use the Go language to achieve automated incremental backup. This article will briefly introduce how to use Go language to perform incremental backup of MySQL database data. 1. Install the Go language environment. First, we need to install the Go language environment locally. You can go to the official website to download the corresponding installation package and install it. 2. Install the corresponding library. The Go language provides many third-party libraries for accessing MySQL databases, among which the most commonly used ones are

How to implement two-way SSL authentication for a MySQL database How to implement two-way SSL authentication for a MySQL database Sep 09, 2023 pm 07:36 PM

How to implement two-way SSL authentication for MySQL database What is two-way SSL authentication? Two-way SSL (SecureSocketsLayer) authentication is an encrypted communication method that requires the server and client to verify each other's identity. In the database, two-way SSL authentication ensures that only authorized users and applications can connect and communicate, improving data security. Preparation Before starting to configure two-way SSL authentication, make sure that the following conditions are met: Obtained

How to make reliable MySQL database connection using Go language? How to make reliable MySQL database connection using Go language? Jun 17, 2023 pm 07:18 PM

With the large amount of data that needs to be stored and processed, MySQL has become one of the most commonly used relational databases in application development. The Go language is becoming more and more popular among developers due to its efficient concurrency processing and concise syntax. This article will lead readers to implement reliable MySQL database connection through Go language, allowing developers to query and store data more efficiently. 1. Several ways for Go language to connect to MySQL database. There are usually three ways to connect to MySQL database in Go language, which are: 1. Third-party library

See all articles