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; } }}