title: Close mysqli connection in another file
body: <p>Let's assume I have 2 php files<br>
  In the first one I have the connection to the database. Since I need it in another php files, I assigned it to a global variable like this.<br></p>
  
  <p><strong>setconnection.php</strong></p>
  
  <pre><code>&lt;?php
  $servername = 'localhost';
  $username = 'root';
  $password = '';
  $dbname = 'database';
  
  // Create connection
  $GLOBALS['connect'] = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($GLOBALS['connect']-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  $db_selected=mysqli_select_db($GLOBALS['connect'],'database');
  mysqli_set_charset($GLOBALS['connect'],'utf8');
  ?&gt;
  </code></pre>
  
  <p>And then I have another php file in which I use the connection from the above php file.<br>
  It is correct to close the connection like this?<br></p>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>include_once "setconnection.php";
  $GLOBALS['connect']-&gt;close();
  </code></pre>