从 MYSQL 更新到 MYSQLI [英] Updating from MYSQL to MYSQLI

查看:25
本文介绍了从 MYSQL 更新到 MYSQLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,由于 MYSQL 已被弃用,并且每个人都不断告诉我要更新,我认为是时候更新了.

So as MYSQL is deprecated and eveyone keeps telling me to update, I thought it was about time I did.

但由于我不习惯 mysqli_*,它对我来说似乎很陌生.当我用 Mysql 编码整个站点时,这不是一个简单的编辑.

But as I'm not used to mysqli_*, it seems alien to me. And it's not a simple edit when I have a whole site coded in Mysql.

所以我想知道:我如何将下面的代码转换成 Mysqli?只是为了在处理查询数据库时为我和其他任何人提供一个良好的起点.

So I'm wondering: How would I transform the below code into Mysqli? Just to give me and anyone else a good starting point when dealing with querying the database.

$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_ 的代码会变成这样..

On reading up and editing my whole site the above code converted to MYSQLI_ would go something like this..

 $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);
    }

推荐答案

您可以从这里下载转换器工具:

You can download a converter tool from here:

https://github.com/philip/MySQLConverterTool

它生成的代码非常粗糙,主要是因为它使用 $GLOBAL 变量实现默认数据库链接参数的方式.(这也便于识别何时有人使用经过转换器的代码.)

The code it generates is pretty gross, mainly because of the way it implements the default database link argument with a $GLOBAL variable. (This also makes it easy to recognize when someone is using code that's gone through the converter.)

这里还有一个 MySQL Shim 库:

There's also a MySQL Shim Library located here:

https://github.com/dshafik/php7-mysql-shim

这篇关于从 MYSQL 更新到 MYSQLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆