& Lt ;? Php * MYSQL database access encapsulation MYSQL data access method. php4 supports process access methods starting with mysql _. php5 supports processes starting with mysqli _ and mysqli object-oriented access methods, this encapsulation class uses mysql _ to encapsulate the general process of data access: 1. connect to the database mysql_connectormysql_pconnect2, Select
Dblink =@ $ func ($ dbhost, $ dbuser, $ dbpw); if ($ halt &&! $ This-> dblink) {$ this-> halt ("The database cannot be connected! ") ;}// SET the query character SET mysql_query (" SET character_set_connection ={$ dbcharset}, character_set_results ={$ dbcharset}, character_set_client = binary ", $ this-> dblink ); // select database $ dbname & @ mysql_select_db ($ dbname, $ this-> dblink);} // select database function select_db ($ dbname) {return mysql_select_db ($ dbname, $ this-> dblink);} // execute the SQL query function query ($ SQL) {$ this-> querynum ++; return mysql_query ($ SQL, $ this-> dblink);} // return Returns the last number of rows affected by the INSERT, UPDATE, or DELETE query associated with the connection handle function affected_rows () {return mysql_affected_rows ($ this-> dblink );} // Obtain the number of rows in the result set. function num_rows ($ result) {return mysql_num_rows ($ result) is valid only for the result set of the select query );} // Obtain the query result function result ($ result, $ row = 0) {return mysql_result ($ result, $ row);} // obtain the ID generated by the previous INSERT operation, function insert_id () {return ($ ID = mysql_insert_id ($ This-> dblink)> = 0? $ Id: $ this-> result ($ this-> query ("SELECT last_insert_id ()"), 0) ;}// extract the current row from the result set, returns the function fetch_row ($ result) {return mysql_fetch_row ($ result) ;}// extracts the current row from the result set in the form of an associated array represented by the key, return function fetch_assoc ($ result) {return mysql_fetch_assoc ($ result);} // extract the current row from the result set in the form of an associated array represented by the field name as key, returns the function fetch_array ($ result) {return mysql_fetch_array ($ result);} // closes the link function close () in the form of an associated array represented by the field name and number as the key () {return mysql_close ($ this-> dblink);} // output a simple error html prompt and terminate the program function halt ($ msg) {$ message ="\ N\ N "; $ message. ="
\ N "; $ message. ="\ N "; $ message. ="\ N "; $ message. =" database error: ". htmlspecialchars ($ msg)." \ n "; $ message. ="\ N "; $ message. =""; Echo $ message; exit ;}}?>