How can i use variables from one function in one file in another function in a different file?
<p>here's what i have:</p>

<p>a database connection script that connects to the database and creates the variable to reference the connection, </p>

<p>next i have a file containing a class with 4 functions that requires the variable for the database connection so that the functions can update the users stats and so on, </p>

<p>my question is how can i use that database connection reference in my class functions without having to declare the database connection part in the class with 4 functions?</p>

<p>my code is below:</p>

<pre><code>&lt;?php

$newTest = new test();
$newTest-&gt;testShow();

class test{

   function __contruct(){

   include('../connection.php'); //script with connection to database and uses $dbc as connection reference
   }


function testShow(){

global $dbc;

$q = "SELECT * FROM levels";
$eq = mysqli_query($dbc, $q);
while($r = mysqli_fetch_array($eq)){

  echo $r;
 }
}

}

?&gt;
</code></pre>
