MySQL database php under MySQL database operation class changed from Discuz

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


/* --------------------------------
System:pt book-pt novel Thief
Code: Jay Less 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 function
*
* @param string $dbhost host name
* @param string $dbuser user
* @param string $DBPW password
* @param string $dbname database name
* @param int $pconnect Whether continuous 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);
}
/**
* Take out a record in 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);
}
/**
* Query 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;
}
/**
* Take the number of affected bars
*
* @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 result bars
*
* @param object $query
* @return int
*/
function Num_rows ($query) {
$query = mysql_num_rows ($query);
return $query;
}
/**
* Fetch the total number of fields
*
* @param object $query
* @return int
*/
function Num_fields ($query) {
Return Mysql_num_fields ($query);
}
/**
* Release result set
*
* @param object $query
* @return BOOL
*/
function Free_result ($query) {
Return Mysql_free_result ($query);
}
/**
* Returns the self-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 enumerated 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 as an object
*
* @param object $query
* @return Object
*/
function Fetch_fields ($query) {
Return Mysql_fetch_field ($query);
}
/**
* Return to 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 describes the MySQL database php under the MySQL database operation class changed from Discuz, including the content of MySQL database, I hope to be interested in PHP tutorial friends 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.