phpwind中的数据库操作类

时间:2021-05-26


<?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);
}
}
?>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章