Class mysql { Private $ db_host; // database host Private $ db_user; // database username Private $ db_pwd; // database username and password Private $ db_database; // database name Private $ conn; // Database Connection ID; Private $ result; // result resource ID for executing the query command Private $ SQL; // SQL execution statement Private $ row; // number of returned entries Private $ coding; // database encoding, GBK, UTF8, gb2312 Private $ bulletin = true; // whether to enable error records Private $ show_error = true; // in the test phase, all errors are displayed, which has security risks and is disabled by default. Private $ is_error = false; // determines whether an error is terminated immediately. the default value is true. we recommend that you do not enable the error because it is annoying to see nothing when there is a problem. /* Constructor */ Public function _ construct ($ db_host, $ db_user, $ db_pwd, $ db_database, $ conn, $ coding ){ $ This-> db_host = $ db_host; $ This-> db_user = $ db_user; $ This-> db_pwd = $ db_pwd; $ This-> db_database = $ db_database; $ This-> conn = $ conn; $ This-> coding = $ coding; $ This-> connect (); } /* Database connection */ Public function connect (){ If ($ this-> conn = "pconn "){ // Permanent link $ This-> conn = mysql_pconnect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd ); } Else { // Even if the link $ This-> conn = mysql_connect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd ); } If (! Mysql_select_db ($ this-> db_database, $ this-> conn )){ If ($ this-> show_error ){ $ This-> show_error ("database unavailable:", $ this-> db_database ); } } Mysql_query ("set names $ this-> coding "); } /* Database execution statements: execute queries, add, modify, delete, and other SQL statements */ Public function query ($ SQL ){ If ($ SQL = ""){ $ This-> show_error ("SQL statement error:", "SQL query statement is empty "); } $ This-> SQL = $ SQL; $ Result = mysql_query ($ this-> SQL, $ this-> conn ); If (! $ Result ){ // Used during debugging. the SQL statement is automatically printed when an error occurs. If ($ this-> show_error ){ $ This-> show_error ("incorrect SQL statement:", $ this-> SQL ); } } Else { $ This-> result = $ result; } Return $ this-> result; } /* Create and add a new database */ Public function create_database ($ database_name ){ $ Database = $ database_name; $ SqlDatabase = 'create database'. $ database; $ This-> query ($ sqlDatabase ); } |