title: Pass MySQL connection to function
body: <p>I am trying to set up a MySQL connection in a main script, and then call various functions depending on what I want to do. I am having trouble passing the connection information to the function.</p>
  
  <p>I have a class "queries" which contains various functions, all which return an array. This is what the code looks like in my main script (calling function normal)</p>
  
  <pre><code>$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name) or die (mysql_error());
  $stats = $queries-&gt;normal($mysqli);
  </code></pre>
  
  <p>And then inside of the queries resource, I have this code:</p>
  
  <pre><code>class queries {
      function normal($mysqli) {
          $query = "SELECT number, first, last FROM roster";
          $roster = $mysqli-&gt;query($query);
  </code></pre>
  
  <p>Then I proceed to do what I need. I cannot get this to work though. I get the error </p>
  
  <pre><code>Call to a member function normal() on a non-object
  </code></pre>
  
  <p>on the line that I call the function in my main file.</p>
  
  <p>This is similar to these questions, but I can't quite figure it out. <br />
  <a href="https://stackoverflow.com/questions/241311/passing-database-connection-by-reference-in-php">Passing database connection by reference in PHP</a> <br />
  <a href="https://stackoverflow.com/questions/394113/ensuring-mysql-connection-works-in-php-function">Ensuring MySQL connection works in PHP function</a></p>
  
  <p>Thank you</p>