Mysql database connection

Source: Internet
Author: User

Mysql database connection
Class MySQL {// Database Section
Var $ DBServer = 'localhost'; // server
Var $ DBName = ''; // Database Name
Var $ DBUser = ''; // Database User
Var $ DBPass = ''; // Database Password
Var $ OnErrorResume = 1; // the error message is disabled.
Var $ LinkID = 0; // connection handle
Var $ QueryID = 0; // query handle
Var $ ResultS = array (); // query result set
Var $ Error = ''; // Error message
Function Connect ($ Srv = "", $ Usr = "", $ Pass = "", $ DB = "") {// Connect to the database
If ($ Srv = "") $ Srv = $ this-> DBServer;
If ($ Usr = "") $ Usr = $ this-> DBUser;
If ($ Pass = "") $ Pass = $ this-> DBPass;
If ($ DB = "") $ DB = $ this-> DBName;
If ($ this-> LinkID = 0 ){
$ This-> LinkID = @ mysql_connect ($ Srv, $ Usr, $ Pass) or die ("database connection failed. Contact the Administrator to fix this problem. ");
}
@ Mysql_select_db ($ DB, $ this-> LinkID) or die ("database selection failed. Contact the Administrator to fix this problem. ");
Return $ this-> LinkID;
}
Function Free () {// release query results
@ Mysql_free_result ($ this-> QueryID );
$ This-> QueryID = 0;
}
Function RowS () {// total number of records queried
If (! $ This-> QueryID) return 0;
Return @ mysql_num_rows ($ this-> QueryID );
}
Function NextRecord () {// next record
If (! $ This-> QueryID) return 0;
$ This-> ResultS = @ mysql_fetch_array ($ this-> QueryID );
}
Function Seek ($ seek ){
If (! $ This-> QueryID) return 0;
@ Mysql_data_seek ($ this-> QueryID, $ seek );
}
Function Query ($ SQL) {// execute the Query
If ($ SQL = "") return 0;
If ($ this-> LinkID = 0) $ this-> Connect ();
If ($ this-> QueryID) $ this-> Free (); // release the original query result
$ This-> QueryID = @ mysql_query ($ SQL, $ this-> LinkID );
$ This-> Error = mysql_error ($ this-> LinkID );
If (! $ This-> QueryID) exit ("$ SQL Execution failed .");
Return $ this-> QueryID;
}
Function GetRecord ($ Name ){
If (! $ This-> QueryID) return 0;
Return $ this-> ResultS [$ Name];
}
}

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.