title: Call to a member function fetch_object() on resource
body: <p>I have written this PHP file which contains SQL to gather all posts in a table.</p>
  
  <pre><code>$selectpost = mysql_query("
  SELECT 
  posts.id,
  COUNT(post_likes.id) AS likes
  
  FROM posts
  
  LEFT JOIN post_likes
  ON posts.id = post_likes.post
  
  GROUP BY posts.id
  
  ");
  
  while($row = $selectpost-&gt;fetch_object()) {
  
  $posts[] = $row;    
  }
  </code></pre>
  
  <p>for some reason i keep getting this error:</p>
  
  <p>Call to a member function fetch_object() on resource in posts.php on line 23 </p>
  
  <p>line 23 is the while loop:</p>
  
  <pre><code>while($row = $selectpost-&gt;fetch_object()) {
  </code></pre>
  
  <p>connecting to database like this:</p>
  
  <pre><code>$db = mysql_connect('localhost', 'account', 'password');
  
  $dbs = mysql_select_db('site');
  </code></pre>
  
  <p>what is wrong, i cant fix it..</p>