title: PHP: Trying to get property of non-object
body: <p>I am working on a function, what returns whether a table exists or not.</p>
  
  <p>But it always notices:</p>
  
  <pre><code>Notice: Trying to get property of non-object [...] on line 10
  </code></pre>
  
  <p>in</p>
  
  <pre><code>1  function table_exists($table) {
  2      
  3      // get the database
  4      global $mysqli;
  5      
  6      // look for tables named $table
  7      $result = $mysqli-&gt;query("SHOW TABLES LIKE $table");
  8      
  9      // if the result has more than 0 rows
  10     if($result-&gt;num_rows &gt; 0) {
  11         return true;
  12     } else {
  13         return false;
  14     }
  15 }
  </code></pre>
  
  <p>the $mysqli var is set like this:</p>
  
  <pre><code>$mysqli = new mysqli(mysqli_host, mysqli_user, mysqli_password, mysqli_database);
  </code></pre>
  
  <p>How to solve that?</p>