_php Skills of database operation class in Phpwind

Source: Internet
Author: User
Tags pconnect

<?php
/* Source: phpwind.net*/

Class DB {
var $query _num = 0;

function DB ($dbhost, $dbuser, $DBPW, $dbname, $pconnect = 0) {
$this->connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect);
}
Function Connect ($dbhost, $dbuser, $DBPW, $dbname, $pconnect = 0) {
$pconnect ==0? @mysql_connect ($dbhost, $dbuser, $DBPW): @mysql_pconnect ($dbhost, $dbuser, $DBPW);
Mysql_errno ()!=0 && $this->halt ("Connect ($pconnect) to MySQL failed");
if ($this->server_info () > ' 4.1 ' && $GLOBALS [' CharSet ']) {
mysql_query ("SET NAMES '". $GLOBALS [' CharSet ']. "'");
}
if ($this->server_info () > ' 5.0 ') {
mysql_query ("SET sql_mode= '");
}
if ($dbname) {
if (! @mysql_select_db ($dbname)) {
$this->halt (' Cannot use database ');
}
}
}
function Close () {
return Mysql_close ();
}
function select_db ($dbname) {
if (! @mysql_select_db ($dbname)) {
$this->halt (' Cannot use database ');
}
}
function Server_info () {
return Mysql_get_server_info ();
}
function query ($SQL, $method = ') {
$GLOBALS [' PW ']== ' pw_ ' or $SQL =str_replace (' Pw_ ', $GLOBALS [' PW '], $SQL);
if ($method = = ' U_b ' && function_exists (' mysql_unbuffered_query ')) {
$query = Mysql_unbuffered_query ($SQL);
}else{
$query = mysql_query ($SQL);
}
$this->query_num++;

echo $SQL. ' <br> '. $this->query_num. ' <br> ';
if (! $query) $this->halt (' Query Error: '. $SQL);
return $query;
}

function Get_one ($SQL) {

$query = $this->query ($SQL, ' u_b ');

$rs =& mysql_fetch_array ($query, MYSQL_ASSOC);

return $rs;
}

function Pw_update ($SQL _1, $SQL _2, $SQL _3) {
$rt = $this->get_one ($SQL _1);
if ($RT) {
$this->update ($SQL _2);
} else{
$this->update ($SQL _3);
}
}

function Update ($SQL) {
$GLOBALS [' PW ']== ' pw_ ' or $SQL =str_replace (' Pw_ ', $GLOBALS [' PW '], $SQL);
if ($GLOBALS [' DB_LP ']==1) {
if (substr ($SQL, 0,7) = = ' REPLACE ') {
$SQL =substr ($SQL, 0,7). Low_priority '. substr ($SQL, 7);
} else{
$SQL =substr ($SQL, 0,6). Low_priority '. substr ($SQL, 6);
}
}
if (function_exists (' mysql_unbuffered_query ')) {
$query = Mysql_unbuffered_query ($SQL);
}else{
$query = mysql_query ($SQL);
}
$this->query_num++;

echo $SQL. ' <br> '. $this->query_num. ' <br> ';

if (! $query) $this->halt (' Update Error: '. $SQL);
return $query;
}

function Fetch_array ($query, $result _type = Mysql_assoc) {
Return mysql_fetch_array ($query, $result _type);
}

function Affected_rows () {
return Mysql_affected_rows ();
}

function Num_rows ($query) {
$rows = mysql_num_rows ($query);
return $rows;
}

function Free_result ($query) {
Return Mysql_free_result ($query);
}

function insert_id () {
$id = mysql_insert_id ();
return $id;
}

function Halt ($msg = ' ") {
Require_once (r_p. ' require/db_mysql_error.php ');
New Db_error ($MSG);
}
}
?>

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.