title: db connection not establish for function
body: <p>I have dbconnect.php file to use all my php files eg., index.php etc.. Also i have functions.php file having all the functions. I always getting nothing when i call a function. </p>
  
  <p><code>setparentid_new($studentid)</code> is a function located in "/functions/functions.php" which path already included in index.php.
  all the functions is not working because of db connection is not there. If i include dbconnect.php in all the functions then only return the results.</p>
  
  <p><code>$parentid</code> is hanging, so below all code not executing.</p>
  
  <p><code>$con</code> not available in functions. In all functions <code>$con</code> need to decalre.
  Please help to pass <code>$con</code> value to each functions globally.</p>
  
  <p><strong>dbconnect.php:</strong></p>
  
  <pre><code>&lt;?php 
  
  define("mysqli_HOST","localhost"); 
  define("mysqli_USER","root"); 
  define("mysqli_PASSWORD",""); 
  define("mysqli_DB","schooldb"); 
  
  $con=mysqli_connect(mysqli_HOST,mysqli_USER,mysqli_PASSWORD,mysqli_DB) or die("Unable to connection. Check connection parameters"); 
  
  ?&gt;
  </code></pre>
  
  <p><strong>index.php:</strong></p>
  
  <pre><code>&lt;?php 
  
  session_start(); 
  ini_set('display_errors', 0); 
  
  include $_SERVER['DOCUMENT_ROOT'] . "/dbs/dbconnect.php"; 
  include $_SERVER['DOCUMENT_ROOT'] . "/functions/functions.php"; 
  ?&gt; 
  &lt;html&gt;
    &lt;div id="bodycontainer"&gt; 
      &lt;?php $insertSQL="INSERT INTO newstudent(col1,col2)values ('data1','data2')"; $result=mysqli_query($con,$insertSQL) or die(mysqli_error()); mysqli_query($con,"UPDATE newstudent SET status ='A' WHERE studid=$studid"); $parentid=setparentid_new($studid); ------- ------ ------ ?&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><code>setparentid_new()</code> function:</strong></p>
  
  <pre><code>setparentid_new($studid) { 
     $sql    = "SELECT * FROM parentsmaster WHERE childid=$studid"; 
     $result = mysqli_query($con,$sql) or die(mysqli_error()); 
     $count = mysqli_num_rows($result); 
  
     if($count==1) { 
       $mynewarray = array(); 
       foreach ($mynewarray as $key =&gt; $row) { 
         $array_depth[$parentid] = $row['parentid']; 
       } 
     } 
  }
  </code></pre>