Migrating from MySQL to MySQLi: A Comprehensive Guide
When migrating your site from MySQL to MySQLi, the primary focus lies on modifying your PHP code. The database itself remains largely unaffected.
PHP Code Substitution
Yes, you can directly replace MySQL functions with their MySQLi counterparts. However, each function in MySQLi takes an additional parameter: the established MySQLi connection. For example, the following MySQL query:
$result = mysql_query("SELECT * FROM users");
Becomes:
$connection = new mysqli(MYSQLI_HOST, MYSQLI_USER, MYSQLI_PASSWORD, MYSQLI_DB);
$result = $connection->query("SELECT * FROM users");
Note: Obsolete MySQL functions such as mysql_connect() and mysql_select_db() are not available in MySQLi.
Additional Considerations
Reference Material
Consult the following resources for more detailed information:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3