PHP Object-oriented thinking design MySQL database operation class

Source: Internet
Author: User
 Host=!empty ($config [' Host '])?      $config [' Host ']: "localhost"; $this->port=!empty ($config [' Port ']?      $config [' Port ']: "3306"; $this->user=!empty ($config [' user '])?      $config [' User ']: "root"; $this->password=!empty ($config [' Password '])?      $config [' Password ']: ""; $this->charset=!empty ($config [' CharSet '])?      $config [' CharSet ']: "UTF8"; $this->dbname=!empty ($config [' dbname '])?      $config [' dbname ']: ""; $this->link= mysql_connect ("{$this->host}:{$this->port}", "{$this->user}", "{$this->password}") O      R die (' execution failed ');      $this->setcharset ($this->charset);   $this->usedbname ($this->dbname);   }//single case design mode static $temp =null;      static function GetClass () {if (!isset (self:: $temp)) {$class-=new self ();      }else{return self:: $temp;   }}//You can set the encoding function Setcharset ($charset) {mysql_query ("Set names $charset");   }//You can set the database function Usedbname ($dbname) {mysql_query ("use $dbname") to be connected; }   You can turn off database function Closedb () {mysql_close ($this->link);   echo "closed successfully!";}         Execute a Delete and modify statement, return the true and false result function exec ($sql) {$result = $this->query ($sql);      return true;         }//Returns a row of query data function Gerrow ($sql) {$result = $this->query ($sql);      $array =mysql_fetch_array ($result);      Mysql_free_result ($result);//release resources return $array;         }//returns multiple rows of query data function getRows ($sql) {$result = $this->query ($sql);         $arr =array ();         while ($array =mysql_fetch_array ($result)) {$arr []= $array;      } mysql_free_result ($result);//Release the resource return $arr;      }//Returns a statement of the data that can return a direct value function Getonedata ($sql) {$result = $this->query ($sql);      $array =mysql_fetch_array ($result);      $data = $array [0];   Mysql_free_result ($result);//release resources return $data;      }//can execute any SQL statement and error handling, or return execution result function query ($sql) {$result =mysql_query ($sql, $this->link); if ($result ===false) {echo]

Execution failure, see the following information: "; Echo
Error code: ". Mysql_errno (); Echo
Error message: ". Mysql_error (); Echo
Error statement: ". $sql; Die (); }else{return $result; } }}

  • 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.