Database operations in phpwind
Last Update:2018-03-18
Source: Internet
Author: User
Database operations in phpwind /* 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 .'
'. $ This-> query_num .'
';
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,) = 'replace '){
$ SQL = substr ($ SQL,). '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 .'
'. $ This-> query_num .'
';
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 );
}
}
?>