phpwind中的数据库操作类

2018-09-07 11:54

阅读:458

  
<?php
/*来源:/

ClassDB{
var$query_num=0;

functionDB($dbhost,$dbuser,$dbpw,$dbname,$pconnect=0){
$this->connect($dbhost,$dbuser,$dbpw,$dbname,$pconnect);
}
functionconnect($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)toMySQLfailed);
if($this->server_info()>4.1&&$GLOBALS[charset]){
mysql_query(SETNAMES.$GLOBALS[charset].);
}
if($this->server_info()>5.0){
mysql_query(SETsql_mode=);
}
if($dbname){
if(!@mysql_select_db($dbname)){
$this->halt(Cannotusedatabase);
}
}
}
functionclose(){
returnmysql_close();
}
functionselect_db($dbname){
if(!@mysql_select_db($dbname)){
$this->halt(Cannotusedatabase);
}
}
functionserver_info(){
returnmysql_get_server_info();
}
functionquery($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(QueryError:.$SQL);
return$query;
}

functionget_one($SQL){

$query=$this->query($SQL,U_B);

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

return$rs;
}

functionpw_update($SQL_1,$SQL_2,$SQL_3){
$rt=$this->get_one($SQL_1);
if($rt){
$this->update($SQL_2);
}else{
$this->update($SQL_3);
}
}

functionupdate($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(UpdateError:.$SQL);
return$query;
}

functionfetch_array($query,$result_type=MYSQL_ASSOC){
returnmysql_fetch_array($query,$result_type);
}

functionaffected_rows(){
returnmysql_affected_rows();
}

functionnum_rows($query){
$rows=mysql_num_rows($query);
return$rows;
}

functionfree_result($query){
returnmysql_free_result($query);
}

functioninsert_id(){
$id=mysql_insert_id();
return$id;
}

functionhalt($msg=){
require_once(R_P.require/db_mysql_error.php);
newDB_ERROR($msg);
}
}
?>


评论


亲,登录后才可以留言!