title: Executing mysqli_query inside a function
body: <p>I have a list of functions in <strong>functions.php</strong>.  I'm upgrading from <em>Mysql</em> to <em>Mysqli</em> because I just learning <em>Mysql</em> is now depreciated.</p>
  <p>I declare my connection in a top levelconnect.php file. The first file is required.</p>
  <p>All my functions use <code>mysql_query(&quot;QUERY&quot;)</code>, which always worked fine. Now I changed all of them to:</p>
  <pre><code>$con-&gt;query(&quot;QUERY&quot;) // ($con is my connection variable)
  </code></pre>
  <p>Now I'm getting a</p>
  <blockquote>
  <p>Fatal error: Call to a member function query() on a non-object in C:\wamp\www\PHP\functions.php on line 241</p>
  </blockquote>
  <p>I don't get why I can query if I'm declaring my variable in my whole file. It should be accessible everywhere, I'm just not sure. This has put my website on hold until I can fix this. Here is a sample function from <strong>functions.php</strong></p>
  <pre><code>function getSiteName()
  {
      $row = $con-&gt;query(&quot;SELECT * FROM siteinfo&quot;)-&gt;fetch_array();
      return $row[&quot;siteName&quot;];
  }
  </code></pre>
  <p>My connection:</p>
  <pre><code>global $con ;
  $con = new mysqli(&quot;localhost&quot;, &quot;itunes89&quot;, &quot;XXXX&quot;,&quot;projectanvil&quot;) or die(&quot;Sorry, were having server connection issues. Please try again later.&quot;);
  </code></pre>