Home >Database >Mysql Tutorial >How to Effectively Migrate from MySQL to MySQLi Syntax?
Question:
Can you migrate MySQL functions to mysqli syntax by replacing mysql_query($sql) with mysqli_query($sql)?
Answer:
While replacing MySQL functions with mysqli equivalents seems like a straightforward approach, it requires a more comprehensive update.
Detailed Conversion Process:
Search and Replace: Replace all mysql_* function calls with their mysqli_* counterparts, as seen in the Function Summary for the MySQLi Extension.
Database Selection:
Additional Considerations:
Example:
Original MySQL code:
$sql = 'SELECT auto_id FROM friend_reg_user WHERE auto_id=' . $info['auto_id']; $result_member = executequery($sql); if ($line_member = mysql_fetch_array($result_member)) { extract($line_member); } else { header("location: index.php"); exit; }
Updated MySQLi code:
$sql = 'SELECT auto_id FROM friend_reg_user WHERE auto_id=' . $info['auto_id']; $result_member = mysqli_query($conn, $sql); if ($line_member = mysqli_fetch_array($result_member)) { extract($line_member); } else { header("location: index.php"); exit; }
The above is the detailed content of How to Effectively Migrate from MySQL to MySQLi Syntax?. For more information, please follow other related articles on the PHP Chinese website!