Ec (2); require_once (& quot; Config. inc. php & quot;); system configuration file & nbsp; * & nbsp; $ DBHOST & quot; localhost & quot; Host Name & nbsp; $ DBUSER & quot; root & quot; script ec (2); script
Require_once ("Config. inc. php"); // System Configuration File
/*
$ DBHOST = "localhost"; // host name
$ DBUSER = "root"; // database username
$ DBPWD = ""; // Password
$ DBNAME = "test"; // Database Name
*/
// Define the Database Class
Class DataBase
{
// Define attributes
Var $ mConnId; // connection ID
Var $ mSqlString; // SQL statement to be executed
Var $ mResultArray; // The result array returned by the Select statement.
// _ Construct (), constructor to establish a database connection
Function _ construct ($ pHost, $ pUser, $ pPwd, $ pDbName ){
$ This-> mConnId = mysql_connect ($ pHost, $ pUser, $ pPwd); // establish a connection
Mysql_select_db ($ pDbName, $ this-> mConnId); // select a database
Mysql_query ("set names 'gbk'"); // sets the database encoding to gbk.
}
// _ Destruct: destructor, disconnected
Function _ destruct (){
Mysql_close ($ this-> mConnId); // There is a problem ......
}
// Execute the SQL statement
Function ExecuteSql (){
Mysql_query ($ this-> mSqlString );
}
// Query data. The returned value is an array of objects. Each element in the array is an object composed of a row of records.
Function Query (){
$ I = 0;
$ Query_result = mysql_query ($ this-> mSqlString, $ this-> mConnId );
While ($ row = mysql_fetch_object ($ query_result )){
$ This-> mResultArray [$ I ++] = $ row;
}
}
} // Class DataBase
// Use the following for testing:
$ Db = new DataBase ($ DBHOST, $ DBUSER, $ DBPWD, $ DBNAME );
$ Db-> mSqlString = "update student set phone = '000000' where id = '000000 '";
$ Db-> ExecuteSql ();
$ Db-> mSqlString = "select * from student where id = '000000 '";
$ Db-> Query ();
Print_r ($ db-> mResultArray); // output the test result