PHP basic------Database Operations classes

Source: Internet
Author: User

classdb{//member Fields    Private$_dbhost; Private$_dbuser; Private$_dbpwd; Private$_dbname; Private$_dbchar; //constructor to initialize data && connect to database && Select Database && Select Character Set     Publicfunction __construct ($dbhost, $dbuser, $dbpwd, $dbname, $dbchar) {//Initializing Data$ This->_dbhost =$dbhost; $ This->_dbuser =$dbuser; $ This->_dbpwd =$dbpwd; $ This->_dbname =$dbname; $ This->_dbchar =$dbchar; //connecting to a database$link = @mysql_connect ($ This->_dbhost,$ This->_dbuser,$ This->_DBPWD) or Die ("database connection Failed!". Mysql_error ()); //Select Databasemysql_select_db ($ This-_dbname, $link); //Select a character setmysql_query ("Set Names".$ This-_dbchar); }        //Execute SQL statements are executed directly for additions and deletions, and return a result set for the query     Publicfunction Query ($sql) {returnmysql_query ($sql); }        //number of statistics records     Publicfunction num ($sql) {//call the Query method of this class to get the result set$result = $ This-query ($sql); //returns the number of records        returnmysql_num_rows ($result); }        //returns the number of rows affected, for insert update     Publicfunction affected () {returnmysql_affected_rows (); }        //Select gets a record     Publicfunction GetOne ($sql) {$result= $ This-query ($sql); //returns an associative array        returnMysql_fetch_assoc ($result); }        //Select to get a two-dimensional array     Publicfunction GetAll ($sql) {$result= $ This-query ($sql); $arr=Array ();  while($rows =Mysql_fetch_assoc ($result)) {$arr []=$rows; }        return$arr; }}

PHP basic------Database Operations classes

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.