title: Call to a member function query() on a non-object
body: <p>I get this error:</p>
  
  <blockquote>
    <p>Call to a member function query() on a non-object.</p>
  </blockquote>
  
  <p>Also when I use other MySQLi functions it gives me the same error but for that function.</p>
  
  <p>My <code>connection.php</code>:</p>
  
  <pre><code>&lt;?php
  $mysqli = new mysqli("localhost","user","pass","db");
  if(mysqli_connect_errno()){
    trigger_error('Connection failed: '.$mysqli-&gt;error);
  }
  
  ?&gt;
  </code></pre>
  
  <p>My function:</p>
  
  <pre><code>function form_year($find, $value, $from, $vehicletype){
      //Query setup
      $autoquery = "SELECT    
                          Year, 
                          Vehicle, 
                          Brand, 
                          Model, 
                          Type, 
                      FROM 
                          vehicle_tbl
                      WHERE
                          Vehicle = '".$vehicletype."'
                      GROUP BY
                          Year";
      $autoresult = $mysqli-&gt;query($autoquery);
  
      $search = array("%value%", "%options%");
      $rows = file_get_contents("tpl/options.html");
      while($row = $autoresult-&gt;fetch_assoc()){
          $replace = array($row[$value], $row[$value]);
          $tr .= str_replace($search, $replace, $rows);
      }
      return str_replace($find, $tr, $from);
  }
  </code></pre>
  
  <p>Function and connection is included where the function is called</p>