Mysql database connection
Class MySQL {// Database Section
Var $ DBServer = 'localhost'; // server
Var $ DBName = ''; // Database Name
Var $ DBUser = ''; // Database User
Var $ DBPass = ''; // Database Password
Var $ OnErrorResume = 1; // the error message is disabled.
Var $ LinkID = 0; // connection handle
Var $ QueryID = 0; // query handle
Var $ ResultS = array (); // query result set
Var $ Error = ''; // Error message
Function Connect ($ Srv = "", $ Usr = "", $ Pass = "", $ DB = "") {// Connect to the database
If ($ Srv = "") $ Srv = $ this-> DBServer;
If ($ Usr = "") $ Usr = $ this-> DBUser;
If ($ Pass = "") $ Pass = $ this-> DBPass;
If ($ DB = "") $ DB = $ this-> DBName;
If ($ this-> LinkID = 0 ){
$ This-> LinkID = @ mysql_connect ($ Srv, $ Usr, $ Pass) or die ("database connection failed. Contact the Administrator to fix this problem. ");
}
@ Mysql_select_db ($ DB, $ this-> LinkID) or die ("database selection failed. Contact the Administrator to fix this problem. ");
Return $ this-> LinkID;
}
Function Free () {// release query results
@ Mysql_free_result ($ this-> QueryID );
$ This-> QueryID = 0;
}
Function RowS () {// total number of records queried
If (! $ This-> QueryID) return 0;
Return @ mysql_num_rows ($ this-> QueryID );
}
Function NextRecord () {// next record
If (! $ This-> QueryID) return 0;
$ This-> ResultS = @ mysql_fetch_array ($ this-> QueryID );
}
Function Seek ($ seek ){
If (! $ This-> QueryID) return 0;
@ Mysql_data_seek ($ this-> QueryID, $ seek );
}
Function Query ($ SQL) {// execute the Query
If ($ SQL = "") return 0;
If ($ this-> LinkID = 0) $ this-> Connect ();
If ($ this-> QueryID) $ this-> Free (); // release the original query result
$ This-> QueryID = @ mysql_query ($ SQL, $ this-> LinkID );
$ This-> Error = mysql_error ($ this-> LinkID );
If (! $ This-> QueryID) exit ("$ SQL Execution failed .");
Return $ this-> QueryID;
}
Function GetRecord ($ Name ){
If (! $ This-> QueryID) return 0;
Return $ this-> ResultS [$ Name];
}
}