title: How to make mysqli connect function?
body: <p>I'm having a problem with a function that connects me to the database using mysqli. What I'm aiming to have is to just type <code>getConnected();</code> where I need the connection.</p>
  
  <p>This is the code:</p>
  
  <pre><code>function getConnected()
  {
      $host = 'localhost';
      $user = 'logintest';
      $pass = 'logintest';
      $db = 'vibo';
  
      $mysqli = new mysqli($host, $user, $pass, $db);
  
      if ($mysqli-&gt;connect_error) {
          die('Connect Error (' . mysqli_connect_errno() . ') '
              . mysqli_connect_error());
      }
  }
  </code></pre>
  
  <p>This is the error I get when I try to use <code>$mysqli</code> after calling <code>getConnected()</code>:</p>
  
  <blockquote>
    <p>Notice: Undefined variable: mysqli in C:\xampp\htdocs\xampp\loginsystem\index.php on line 19</p>
  </blockquote>