MYSQL to MYSQLi

Biswarup Ghoshal
1 min readFeb 26, 2020

Steps to follow for conversion to a Legacy PHP application from MYSQL to MYSQLi

  1. Find mysql_query, then replace with mysqli_query($conn
  2. Find mysql_fetch_array, then replace with mysqli_fetch_array
  3. Find mysql_num_rows, then replace with mysql_num_rows
  4. Find mysql_error, then replace with mysqli_error
  5. Find mysql_insert_id, then replace with mysqli_insert_id
  6. Find mysql_fetch_object, then replace with mysql_fetch_object
  7. Any mysql_fetch_object($result) or die(mysql_error()) to be replaced by mysqli_fetch_object($result)

Open Connection Class -

$conn = mysqli_connect(“127.0.0.1”, “root”, “<<PASSWORD>>”, “<<DB>>”);
if (!$conn) {
echo “Error: Unable to connect to MySQL.” . PHP_EOL;
echo “Debugging errno: “ . mysqli_connect_errno() . PHP_EOL;
echo “Debugging error: “ . mysqli_connect_error() . PHP_EOL;
exit;
}

Close Connection Class

mysqli_close($conn)

--

--