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

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

问题描述

因此,由于不建议使用MYSQL,并且eveyone不断告诉我进行更新,所以我认为这是我做的时间.

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天全站免登陆