phpwind中的数据库操作类_php教程-查字典教程网
phpwind中的数据库操作类
phpwind中的数据库操作类
发布时间:2016-12-29 来源:查字典编辑
摘要:

<?php

/*来源:phpwind.net*/

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

}

}

?>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新php教程学习
    热门php教程学习
    编程开发子分类