title: How to convert PDO to mysqli?
body: <p>I have a login screen in which the user inputs their username and password. I managed to connect to the database using PDO but I have to change it to mysqli. Could someone please help me convert it to mysqli. Thanks in advance. </p>
  
  <p>PDO:</p>
  
  <pre><code>&lt;?php
  try {
          $database = new PDO('mysql:host=localhost;dbname=myfiles', 'root', '',array(PDO::ATTR_ERRMODE =&gt; PDO::ERRMODE_EXCEPTION));
          $query = "SELECT * FROM users WHERE Username = ? AND Password = ?";
  
          $userParam = array($_POST["Uname"], $_POST["Pass"]);
          $st = $database-&gt;prepare($query);
          $st-&gt;execute($userParam);
  
          $getResults = $st-&gt;fetch(PDO::FETCH_ASSOC);
  
          session_start();
  
          $_SESSION['details']['username'] = $getResults['Username'];
          $_SESSION['details']['password'] = $getResults['Password'];
  
          unset($database);
          header("Location: index.php");
      }
  catch(PDOException $e)
      {
     print "Error!: " . $e-&gt;getMessage() . "&lt;br/&gt;";
      exit();
      }
    ?&gt;
  </code></pre>
  
  <p>Mysqli (This is what I have tried)</p>
  
  <pre><code>&lt;?php
  
  try {
  
  $database =  mysqli_connect("localhost", "root", "", "myfiles");
  $query = mysqli_query("SELECT * FROM users WHERE Username = ? AND Password = ?");
  
          $userParam = array($_POST["Uname"], $_POST["Pass"]);
          $st = $database-&gt;prepare($query);
          $st-&gt;execute($userParam);
  
          $getResults = mysqli_fetch_assoc($query);
  
          session_start();
  
          $_SESSION['details']['username'] = $results['Username'];
          $_SESSION['details']['password'] = $results['Password'];
  
          unset($database);
          header("Location: index.php");
  
          } catch (Exception $e ) {
          print "Error!: " . $e-&gt;getMessage() . "&lt;br/&gt;";
          exit();
  }
  
  ?&gt;
  </code></pre>
  
  <p>Error when running Mysqli code:</p>
  
  <pre><code>Warning: mysqli_query() expects at least 2 parameters, 1 given in G:\xampp\htdocs\old\drop\login.php on line 39
  
  Fatal error: Call to a member function execute() on a non-object in G:\xampp\htdocs\old\drop\login.php on line 43
  </code></pre>
  
  <p>Update:</p>
  
  <p>Mysqli</p>
  
  <pre><code>&lt;?php
  
         try {
  
      $database =  mysqli_connect("localhost", "root", "", "myfiles");
      $query = "SELECT * FROM users WHERE Username = ? AND Password = ?";
  
              $userParam = array($_POST["Uname"], $_POST["Pass"]);
              $st = $database-&gt;prepare($query);
              $st-&gt;execute($userParam);
  
              $getResults = mysqli_fetch_assoc($st);
  
              session_start();
  
              $_SESSION['details']['username'] = $getResults['Username'];
              $_SESSION['details']['password'] = $getResults['Password'];
  
              unset($database);
              header("Location: index.php");
  
              } catch (Exception $e ) {
              print "Error!: " . $e-&gt;getMessage() . "&lt;br/&gt;";
              exit();
      }
  
      ?&gt;
  
      "Waiting for localhost"
  </code></pre>