<?
Class Mysql {
Var $ linkid;
Var $ db_host;
Var $ db_user;
Var $ db_pwd;
Var $ db_name;
Var $ querynum = 0;
Var $ selectid;
Var $ result = null;
Var $ pconnect = true;
// Constructor. Database parameters must be included in class initialization.
Function Mysql ($ db_host, $ db_user, $ db_pwd, $ db_name, $ pconnect = true ){
$ This-> db_host = $ db_host;
$ This-> db_user = $ db_user;
$ This-> db_pwd = $ db_pwd;
$ This-> db_name = $ db_name;
If ($ this-> pconnect ==$ pconnect ){
$ This-> linkid = @ mysql_pconnect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd );
}
Else {
$ This-> linkid = @ mysql_connect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd );
}
If ($ this-> linkid ){
If ($ this-> db_name! = ""){
$ Dbselect = @ mysql_select_db ($ this-> db_name) or $ this-> mysql_err ("database not exists ");
}
}
Else {
$ This-> mysql_err ("cannot connect the database server, pls chk your password ");
}
// $ This-> query ("set names 'utf8 '");
}
// Execute SQL statements
Function query ($ SQL ){
$ This-> result = @ mysql_query ($ SQL, $ this-> linkid) or $ this-> mysql_err ("SQL statement". $ SQL. "error ");
$ This-> querynum ++;
Return $ this-> result;
}
Function fetch_array ($ SQL ){
Return mysql_fetch_array ($ SQL, MYSQL_ASSOC );
}
// Used to count the number of records
Function Number ($ SQL ){
$ This-> result = $ this-> query ($ SQL );
$ Number = mysql_num_rows ($ this-> result );
$ This-> free ();
Return $ number;
}
// Obtain a record
Function getrow ($ SQL ){
$ This-> query ($ SQL );
$ Row = mysql_fetch_array ($ this-> result, MYSQL_ASSOC );
$ This-> Free ();
Return $ row;
}
// Retrieve all records
Function GetRows ($ SQL ){
$ This-> result = $ this-> query ($ SQL );
While ($ ROW = mysql_fetch_array ($ this-> result, mysql_assoc ))
{
$ Allrows [] = $ row;
}
$ This-> Free ();
Return $ allrows;
}
// Obtain the ID field of the current insert
Function InsertID (){
$ Id = mysql_insert_id ();
Return $ id;
}
// Close the database
Function Close (){
@ Mysql_close ($ this-> linkid );
}
// Print the error message
Function Mysql_err ($ msg ){
Echo $ msg;
Exit;
}
// Release
Function Free (){
@ Mysql_free_result ($ this-> result );
$ This-> result = null;
}
}
?>