因此,当MYSQL被弃用并且eveyone不断告诉我更新时,我认为这是我的时间.
但是因为我不习惯mysqli_*,这对我来说似乎很陌生.当我在Mysql中编写整个站点时,这不是一个简单的编辑.
所以我想知道:我如何将下面的代码转换成Mysqli?在处理查询数据库时,只是给我和其他任何人一个很好的起点.
$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){
}
Run Code Online (Sandbox Code Playgroud)
编辑:在阅读和编辑我的整个网站时,上面的代码转换为MYSQLI_将会是这样的..
$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")) {
printf("Error: %s\n", $mysqli->error);
}
Run Code Online (Sandbox Code Playgroud)
Bar*_*mar 25
您可以从这里下载转换器工具:
https://github.com/philip/MySQLConverterTool
它生成的代码非常严重,主要是因为它使用$GLOBAL
变量实现默认数据库链接参数的方式.(当有人使用经过转换器的代码时,这也很容易识别.)
这里还有一个MySQL Shim Library:
https://github.com/dshafik/php7-mysql-shim