MYSQL to MYSQLi
1 min readFeb 26, 2020
Steps to follow for conversion to a Legacy PHP application from MYSQL to MYSQLi
- Find mysql_query, then replace with mysqli_query($conn
- Find mysql_fetch_array, then replace with mysqli_fetch_array
- Find mysql_num_rows, then replace with mysql_num_rows
- Find mysql_error, then replace with mysqli_error
- Find mysql_insert_id, then replace with mysqli_insert_id
- Find mysql_fetch_object, then replace with mysql_fetch_object
- 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)