class for MVC to return fetch_array/object results
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; } }
returns
[Wed May 30 11:55:42 2012] [error] [client] PHP Fatal error: Call to a member function mysql_query() on a non-object in /var/www/httpdocs/test/mysql.php on line 30
line 30
$this->result = $this->connection->mysql_query($this->query);
ill go nuts. >.<
Because mysql_query:
Returns a MySQL link identifier on success or FALSE on failure.
so $this->connection is not object.
Please use PDO driver or MySQLi, mysql_* extensions will be deprecated in the future.
Good PDO examples
Here is your problem
$this->connection = mysql_select_db($database);
mysql_select_db
returns bool
But please take a look on PDO or mysqli