I have read the DB class in Discuz. it is simple and practical. I have changed it and used it. the Source Code after modification is as follows, the member variables and methods are described as follows: & amp; lt ;? Php/*** bymckee & amp; w
I have read the DB class in Discuz. it is simple and practical. I have changed it and used it. the Source Code after modification is as follows, the member variables and methods are described as follows:
Host = $ host; $ this-> username = $ username; $ this-> password = $ password; $ this-> dbname = $ dbname; $ this-> charset = $ charset; if ($ pconnect) {if (! $ This-> conn = mysql_pconnect ($ this-> host, $ this-> username, $ this-> password )) {$ this-> halt ('cannot connect to mysql') ;}} else {if (! $ This-> conn = mysql_connect ($ this-> host, $ this-> username, $ this-> password )) {$ this-> halt ('cannot connect to mysql') ;}} mysql_select_db ($ this-> dbname ); mysql_query ("set names {$ this-> charset}");} // using mysql_unbuffered_query will not use the buffer zone, but it also has its disadvantages, for example, you cannot use mysql_num_rows to obtain the number of results. Function query ($ SQL, $ type = '', $ cachetime = FALSE) {$ func = $ type = 'unbuffered' & @ function_exists ('MySQL _ unbuffered_query ')? 'MySQL _ unbuffered_query ': 'MySQL _ query'; if (! ($ Query = $ func ($ SQL, $ this-> conn) & $ type! = 'Silent') {$ this-> halt ('MySQL Query error', $ SQL);} $ this-> querynum ++; $ this-> histories [] = $ SQL; return $ query;} // The associated array public function fetch_array ($ query, $ result_type = MYSQL_ASSOC) is returned by default) {return mysql_fetch_array ($ query, $ result_type);} // return the function result_first ($ SQL) in the first column of the first row {$ query = $ this-> query ($ SQL ); return $ this-> result ($ query, 0);} // return the first row of data function fetch_first ($ SQL) {$ query = $ this-> query ($ SQL); r Eturn $ this-> fetch_array ($ query);} function fetch_all ($ SQL, $ id = '') {$ arr = array (); $ query = $ this-> query ($ SQL); while ($ data = $ this-> fetch_array ($ query) {$ id? $ Arr [$ data [$ id] = $ data: $ arr [] = $ data;} return $ arr;} function affected_rows () {return mysql_affected_rows ($ this-> conn);} function error () {return ($ this-> conn )? Mysql_error ($ this-> conn): mysql_error ();} function errno () {return intval ($ this-> conn )? Mysql_errno ($ this-> conn): mysql_errno ();} function result ($ query, $ row) {$ query = @ mysql_result ($ query, $ row ); return $ query;} function num_rows ($ query) {$ query = mysql_num_rows ($ query); return $ query;} // number of returned fields function num_fields ($ query) {return mysql_num_fields ($ query);} function free_result ($ query) {return mysql_free_result ($ query);} // if the column type of AUTO_INCREMENT is BIGINT, mysql_insert_id () the returned value is incorrect, Yes, you can use LAST_INSERT_ID () to replace function insert_id () {return ($ id = mysql_insert_id ($ this-> conn)> = 0? $ Id: $ this-> result ($ this-> query ("SELECT last_insert_id ()"), 0);} function fetch_row ($ query) {$ query = mysql_fetch_row ($ query); return $ query;} // Obtain the column information function fetch_fields ($ query) {return mysql_fetch_field ($ query);} function version () {return mysql_get_server_info ($ this-> conn);} function close () {return mysql_close ($ this-> conn );} // public function halt ($ message = '', $ SQL ='') {$ error = mysql_error (); $ errorno = mysql_errno (); $ s = ''; if ($ message) {$ s ="Error info:$ Message
";} If ($ SQL) {$ s. ='SQL:'.Html specialchars ($ SQL ).'
';} $ S. ='Error:'. $ Error .'
'; $ S. ='Errno:'. $ Errorno .'
'; Exit ($ s) ;}}?>