Discuz x3.0 discuz7 Phpmysql Operation class

Source: Internet
Author: User
Tags pconnect
Copy CodeThe code is as follows:


/*
* MySQL Database connection class
* mysql.class.php 2009.04.15 by Hackbaby
*/
Class Dbstuff {
var $version = ';
var $querynum = 0;
var $link = null;
Connecting to a database
Function Connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect = 0, $halt = TRUE, $dbcharset 2 = ") {
$conn = Empty ($pconnect)? ' Mysql_connect ': ' Mysql_pconnect ';
if (! $this->link = @ $conn ($dbhost, $dbuser, $DBPW, 1)) {
$halt && $this->halt (' Can not connect to MySQL server ');
} else {
if ($this->version () > ' 4.1 ') {
Global $charset, $dbcharset;
$dbcharset = $dbcharset 2? $dbcharset 2: $dbcharset;
$dbcharset =! $dbcharset && in_array (Strtolower ($charset), Array (' GBK ', ' Big5 ', ' utf-8 ')? Str_replace ('-', ', $charset): $dbcharset;
$serverset = $dbcharset? ' Character_set_c: ';
$serverset. = $this->version () > ' 5.0.1 '? (Empty ($serverset)? '' : ',').' Sql_mode=\ ' \ '): ';
$serverset && mysql_query ("SET $serverset", $this->link);
}
$dbname && @mysql_select_db ($dbname, $this->link);
}
}
Select Database
function select_db ($dbname) {
Return mysql_select_db ($dbname, $this->link);
}
How to return a database after execution
function Fetch_array ($query, $result _type = Mysql_assoc) {
Return mysql_fetch_array ($query, $result _type);
}
Returns the return value after the Fetch_array method executes
function Fetch_first ($sql) {
return $this->fetch_array ($this->query ($sql));
}
Returns the return value after the result method executes
function Result_first ($sql) {
return $this->result ($this->query ($sql), 0);
}
Performing operations on a database
function query ($sql, $type = ") {
Global $debug, $discuz _starttime, $sqldebug, $sqlspenttimes;
Determine Debug Debug
if (defined (' Sys_debug ') && sys_debug) {
@include_once web_root. " /include/debug.func.php ';
SQLDebug ($sql);
}
//
$func = $type = = ' unbuffered ' && @function_exists (' Mysql_unbuffered_query ')?
' Mysql_unbuffered_query ': ' mysql_query ';
if (! ( $query = $func ($sql, $this->link))) {
if (In_array ($this->errno (), Array (2006)) && substr ($type, 0, 5)! = ' RETRY ') {
$this->close ();
Require './config.inc.php ';
$this->connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect, True, $dbcharset);
$this->query ($sql, ' RETRY '. $type);
} elseif ($type! = ' SILENT ' && substr ($type, 5)! = ' SILENT ') {
$this->halt (' MySQL Query Error ', $sql);
}
}
Query bar number plus 1
$this->querynum++;
return $query;
}
Gets the number of record rows affected by the previous MySQL operation
function Affected_rows () {
Return Mysql_affected_rows ($this->link);
}
Text error message for database
Function error () {
Return ($this->link) mysql_error ($this->link): Mysql_error ());
}
Returns the numeric encoding of the error message in the previous MySQL operation
function errno () {
Return Intval ($this->link) Mysql_errno ($this->link): Mysql_errno ());
}
Returns the results of a database operation
function result ($query, $row = 0) {
$query = @mysql_result ($query, $row);
return $query;
}
Returns the number of operations such as database queries
function Num_rows ($query) {
$query = mysql_num_rows ($query);
return $query;
}
Get the number of fields in the result set
function Num_fields ($query) {
Return Mysql_num_fields ($query);
}
Releasing the resulting memory
function Free_result ($query) {
Return Mysql_free_result ($query);
}
Gets the ID generated by the INSERT operation in the previous step
function insert_id () {
return ($id = mysql_insert_id ($this->link)) >= 0? $id: $this->result ($this->query ("Select last_insert_id ()"), 0);
}
Returns the query result as an array
function Fetch_row ($query) {
$query = Mysql_fetch_row ($query);
return $query;
}
Get column information from the result set and return as an object
function Fetch_fields ($query) {
Return Mysql_fetch_field ($query);
}
Get the version of MySQL
Function version () {
if (Empty ($this->version)) {
$this->version = mysql_get_server_info ($this->link);
}
return $this->version;
}
Close connection
function Close () {
Return Mysql_close ($this->link);
}
Error hints
function Halt ($message = ', $sql = ') {
Define (' Cache_forbidden ', TRUE);
Require_once Web_root. './include/db_mysql_error.inc.php ';
}
}
?>

The above describes the Discuz x3.0 discuz7 Phpmysql operation class, including Discuz x3.0 aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.