php Mysql类(查询 删除 更新)
php Mysql类一般都包括了几乎我们常用的数据库操作方法,这里只提供了查询 删除 更新三种操作,算不是很全只是一个简单的数据库查询类了,实例代码如下:
- class mysql
- {
- private $host;
- private $user;
- private $pass;
- private $database;
- private $charset;
- function __construct($host,$user,$pass,$database,$charset)
- {
- $this--->host=$host;
- $this->user=$user;
- $this->pass=$pass;
- $this->database=$database;
- $this->charset=$charset;
- $this->connect();
- }
- private function connect()
- {
- mysql_connect($this->host,$this->user,$this->pass) or die ("连接数据库服务器失败!");
- mysql_select_db($this->database) or die ("连接数据库失败!");
- mysql_query("set names $this->charset");
- }
- function select($sql,$tab,$col,$value)
- {
- $select=mysql_query("select $sql from $tab where $col=$value");
- $row=mysql_fetch_array($select);
- return $row;
- }
- function insert($tab,$col,$value)
- {
- mysql_query("INSERT INTO $tab($col)values($value)");
- }
- function update($tab,$col,$new_value,$colm,$value)
- {
- mysql_query("UPDATE $tab SET $col=$new_value where $colm=$value");
- }
- function delete($tab,$col,$value)
- {
- mysql_query("DELETE FROM $tab where $col=$value");
- }
- function close()
- {
- mysql_close();
-
- }
- }
-
-
-
-
-
-
-