title: Safe way to connect database with php using MySQLi
body: <p>I just cut down my long code to small so its easy to understand. I am building php based website. I am using <code>MySQLi</code> as i know some <code>MySQL</code>. And for me <code>PDO</code> is hard to learn in small time period.</p>
  
  <p>I created three files </p>
  
  <pre><code> - db.con.php
   - index.php
   - logout.php
  </code></pre>
  
  <p>I will post my all three files and i just want to know if its <code>safe</code> or there is any <code>Vulnerability</code> </p>
  
  <p>And i thanks to all who see my question and appreciate answer alot. </p>
  
  <p><strong>db.con.php</strong></p>
  
  <pre><code>&lt;?php
  //db.con.php
  class DB { 
      protected $db_name = 'demo';
      protected $db_user = 'root';
      protected $db_pass = '';
      protected $db_host = 'localhost';
  
      public function connect() { 
          $DBerror = 'Database Error';
          $connection = ($GLOBALS["___mysqli_ston"] = mysqli_connect($this-&gt;db_host,  $this-&gt;db_user,  $this-&gt;db_pass)) or die($DBerror); 
          ((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE $this-&gt;db_name")) or die($DBerror); 
          return true; 
      }
  } 
  
  $db = new DB();
  $db-&gt;connect();
  
  //start session
  session_start();
  ?&gt;
  </code></pre>
  
  <p><strong>index.php</strong></p>
  
  <pre><code>&lt;?php
  require_once 'db.con.php';
  $userID = $_GET['userID'];
  $userID = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $userID);
  
  $CheckQuery = mysqli_query($GLOBALS["___mysqli_ston"], "SELECT * FROM users WHERE id='$userID'");
  
  $VerifyID = mysqli_num_rows($CheckQuery);
  if ($VerifyID !== 1){
      header("Location: logout.php");
  }
  
  while ($row = mysqli_fetch_assoc($CheckQuery)) {
      $id = $row['id'];
      $name = $row['name'];
  }
  
  echo "My id is $id and my name is $name";
  
  ?&gt;
  </code></pre>
  
  <p><strong>And last logout.php</strong></p>
  
  <pre><code>&lt;?php
  //logout.php
  session_start();
  
  session_destroy();
  echo "Logout successful";
  ?&gt;
  </code></pre>