title: Trouble converting PDO query to MySQLi
body: <p>I have a query that is working fine in PDO but I am needing to convert the query to MySQLi to be compatible with an older server.</p>
  
  <p>Here is the PDO query:</p>
  
  <pre><code>$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
  $sql = "SELECT * FROM users WHERE username=:username";
  $st = $conn-&gt;prepare( $sql );
  $st-&gt;bindValue( ":username", $username, PDO::PARAM_STR );
  $st-&gt;execute();
  
  while ( $row = $st-&gt;fetch() ) {
    $db_username = $row['username'];
    $db_password = $row['password'];
  }
  </code></pre>
  
  <p>Here is what I have to MySQLi, but it doesn't seem to be working:</p>
  
  <pre><code>$mysqli = new mysqli( 'localhost', DB_USERNAME, DB_PASSWORD, DB_NAME );
  $username = mysqli_real_escape_string($mysqli, $username);
  $query = "SELECT * FROM users WHERE username=$username";
  if ($result = $mysqli-&gt;query($query)) {
  while ($obj = $result-&gt;fetch_object()) {
    $db_username = $obj-&gt;username;
    $db_password = $obj-&gt;password;
  }
  mysqli_free_result($result);
  }
  </code></pre>
  
  <p>Any help would be very much appreciated :)</p>