MySQL database operations in PHP

Source: Internet
Author: User
Class dbconn {var $ conn = 0; function dbconn ($ dbhost, $ dbuser, $ dbpw, $ dbname) {$ this-> conn = mysql_connect ($ dbhost, $ dbuser, $ dbpw );! $ This-> conn & $ this-> halt ("connect to MySQL failed"); $ serverinfo = mysql_get_server_info ($ this-> conn ); if ($ serverinfo> '4. 1' & $ globals ['charset']) {mysql_query ("set character_set_connection = ". $ globals ['charset']. ", character_set_results = ". $ globals ['charset']. ", character_set_client = binary", $ this-> conn);} if ($ serverinfo> '5. 0 ') {mysql_query ("set SQL _mode ='' ", $ this-> conn);} if ($ dbname &&! @ Mysql_select_db ($ dbname, $ this-> conn) {$ this-> halt ('cannot use database');} function select_db ($ dbname) {If (! @ Mysql_select_db ($ dbname, $ this-> conn) {$ this-> halt ('cannot use database');} function server_info () {return mysql_get_server_info ($ this-> conn);} function insert_id () {$ arr = $ this-> fetch_array ('select last_insert_id () as id '); return $ arr ["ID"];} function get_value ($ SQL, $ offset = 0, $ field = 0) {$ RT = $ this-> fetch_all ($ SQL ); if (isset ($ RT [$ offset] [$ field]) {return $ RT [$ offset] [$ field];} return False;} function query ($ SQL, $ method = NULL, $ error = true) {$ query = mysql_query ($ SQL, $ this-> conn );! $ Query & $ error & $ this-> halt ('query error :'. $ SQL); return $ query;} function fetch_array ($ SQL) {$ query = $ this-> query ($ SQL); Return mysql_fetch_array ($ query );} function fetch_all ($ SQL) {$ arr = array (); $ query = $ this-> query ($ SQL); While ($ DATA = mysql_fetch_array ($ query )) {$ arr [] = $ data;} return $ arr;} function affected_rows () {return mysql_affected_rows ($ this-> conn);} function num_rows ($ SQL) {$ query = $ this-> query ($ SQL); If (! Is_bool ($ query) {return mysql_num_rows ($ query);} return 0;} function num_fields ($ SQL) {$ query = $ this-> query ($ SQL ); return mysql_num_fields ($ query);} function escape_string ($ Str) {return mysql_escape_string ($ Str);} function free_result () {$ void = func_get_args (); foreach ($ void as $ query) {If (is_resource ($ query) & get_resource_type ($ query) === 'mysql result') {mysql_free_result ($ query );}} unset ($ void);} function close () {$ this-> free_result (); Return @ mysql_close ($ this-> conn);} function halt ($ MSG = NULL) {exit ($ MSG. '<br/> '. $ SQL. '<br/> '. mysql_error ());}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.