Home >Database >Mysql Tutorial >How to Migrate from MySQL to MySQLi for Database Queries: A Step-by-Step Guide
Updating from MySQL to MySQLi for Querying Databases
As MySQL has been deprecated, many developers are updating their code to use MySQLi. However, the transition can be challenging for those unfamiliar with MySQLi's syntax. This article provides a starting point for transforming a MySQL query into its MySQLi equivalent.
Original MySQL Code:
$sql_follows="SELECT * FROM friends WHERE user1_id=".$_SESSION['id']." AND status=2 OR user2_id=".$_SESSION['id']." AND status=2"; $query_follows=mysql_query($sql_follows) or die("Error finding friendships"); if($query_follows>0){ }
MySQLi Code Equivalent:
$Your_SQL_query_variable = mysqli_query($connectionvariable, "SELECT * FROM friends WHERE user1_id=".$_SESSION['id']." AND status=2 OR user2_id=".$_SESSION['id']." AND status=2"); if ($mysqli->errno) { printf("Error: %s\n", $mysqli->error); }
Additional Tools and Resources:
MySQL Converter Tool: https://github.com/philip/MySQLConverterTool
MySQL Shim Library: https://github.com/dshafik/php7-mysql-shim
Important Considerations:
The above is the detailed content of How to Migrate from MySQL to MySQLi for Database Queries: A Step-by-Step Guide. For more information, please follow other related articles on the PHP Chinese website!