MVC 返回 fetch_array/object 结果的类
class DbDriver{ private $connection; private $query; private $result; public function connect() { $host = 'localhost'; $user = ''; $password = ''; $database = ''; $this->connection = mysql_connect($host, $user, $password); $this->connection = mysql_select_db($database); return TRUE; } public function disconnect() { $this->connection->mysql_close(); return TRUE; } public function prepare($query) { $this->query = $query; return TRUE; } public function query() { if (isset($this->query)) { $this->result = $this->connection->mysql_query($this->query); return TRUE; } return FALSE; } public function fetch($type = 'object') { if (isset($this->result)) { switch ($type) { case 'array': $row = $this->result->mysql_fetch_array(); break; case 'object': default: $row = $this->result->mysql_fetch_object(); break; } return $row; } return FALSE; } }
返回
[2012 年 5 月 30 日星期三 11:55:42] [错误] [客户端] PHP 致命错误:在第 30 行的 /var/www/httpdocs/test/mysql.php 中的非对象上调用成员函数 mysql_query()
第 30 行
$this->result = $this->connection->mysql_query($this->query);
生病疯了。>.<