一个php类,封装了php操作mysql的基本方法,包含数据库链接,基本的数据查询方法
<?PHP class Database { var $db; var $result; var $lastQuery; var $numQueries = 0; var $error; var $showErrors = true; function Database($host, $user, $password, $dbname) { $this->db = mysql_connect($host, $user, $password) or die(mysql_error()); mysql_select_db($dbname, $this->db) or die(mysql_error()); } function query($sql) { $this->error = ""; $this->lastQuery = $sql; if($this->showErrors) $this->result = mysql_query($sql, $this->db) or die(mysql_error() . "<br/>--<br/>$sql"); else $this->result = mysql_query($sql, $this->db) or ($this->error = mysql_error()); $this->numQueries++; } } ?>