Php connection to mysql database class _ PHP Tutorial

Source: Internet
Author: User
Tags mysql tutorial
Php connection to mysql database class. Php connection to mysql database class this is a simple and practical php connection to mysql database class, only data query, returned array set, obtain the new id, obtain the record row, and other simple mysql database php connection mysql database class. this is a simple and practical php connection to the mysql database class. it only performs data queries and returns the array set, obtain the new id, obtain the record line, and other simple mysql database connection code.

Php Tutorial connection to mysql tutorial database tutorial class
This is a simple and practical php connection to the mysql database class. it only performs data queries, returns array sets, obtains new IDs, obtains record rows, and other simple mysql database connection code.
*/

Class database {

Var $ dblink;

Function connect ($ dbhost, $ dbuser, $ dbpw, $ dbname = ""){
$ This-> dblink = mysql_connect ($ dbhost, $ dbuser, $ dbpw );

Mysql_query ("set names 'utf8 '");
Mysql_query ("set character_set_client = utf8 ");
Mysql_query ("set character_set_results = utf8 ");

If ($ dbname ){
Mysql_select_db ($ dbname, $ this-> dblink );
}
}

Function query ($ SQL ){
$ Result = mysql_query ($ SQL, $ this-> dblink );
Return $ result;
}

Function fetch_array ($ result ){
Return mysql_fetch_array ($ result );
}

Function insert_id (){
$ Id = mysql_insert_id ();
Return $ id;
}

Function getrow ($ SQL ){
$ Result = mysql_query ($ SQL, $ this-> dblink );
Return mysql_fetch_assoc ($ result );
}

Function getdetailrow ($ SQL ){
$ Result = mysql_query ($ SQL, $ this-> dblink );
Return mysql_fetch_array ($ result );
}
// Www. bKjia. c0m
Function close (){
Mysql_close ($ this-> dblink );
}
}

// Call method

$ Db = new database;
$ Db-> connect ($ dbhost, $ dbuser, $ dbpw, $ dbname );
Unset ($ dbhost, $ dbuser, $ dbpw, $ dbname );


?>

Logging and other simple mysql databases...

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.