When i get this error:
Call to a member function query() on a non-object
Now when im going to the line it specifies then i see this:
// Count the rows of a table
$query = $this->c->query("SELECT COUNT(*) as `rows` FROM ".$query) or die($this->c->error);
$row = $query->fetch_assoc();
$result = $row['rows'];
return $result;
Now after some trying i found out that it gives me the right result when i do die($result); before returning it, there it gives the result i need.
When i check what line calls the function then i see this:
if($this->num_rows("accounts WHERE id='".$_SESSION['user_id']."'") == 0)
My class i build like this:
I make a class Db where there is a function num_rows, then i make a class User that extends the Db class, in the constructor of the User class i initialize the Db class by doing parent::__construct(); i’m 100% sure the class gets initialized since i can do real-escape strings but not execute any queries O.o anybody that can help me with this?
Some extra information:
when i print_r my connection it gives this:
mysqli Object ( [affected_rows] => 1 [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ [client_version] => 50008 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 1 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.16 [server_version] => 50516 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 715 [warning_count] => 0 ) mysqli Object ( [affected_rows] => 1 [client_info] => mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ [client_version] => 50008 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [field_count] => 1 [host_info] => localhost via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.16 [server_version] => 50516 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 715 [warning_count] => 0 )
Question i got in my head is why it got 2 mysqli objects in it??
Db class = http://pastebin.com/yvDij0kG
User class = http://pastebin.com/ndwa2YRr
Ok found my own bug :p was because i was overriding the constructor and because of that i couldn’t initiate my object outside it’s own constructor.