将大型网站从MySQL切换到MySQLi [英] Switch large website from MySQL to MySQLi

查看:118
本文介绍了将大型网站从MySQL切换到MySQLi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从MySQL切换到MySQLi,但是我有一个非常大的网站.

I want to switch from MySQL to MySQLi, but I have a very large website.

我读到 https://wikis.oracle.com/display/mysql/Converting + to + MySQLi 可以帮助我,我阅读如何将该mysql更改为mysqli?.它说我可以通过在函数中添加一个"i"来替换大多数函数,并且应该开始寻找错误.

I read that https://wikis.oracle.com/display/mysql/Converting+to+MySQLi could help me and I read How could I change this mysql to mysqli?. It says that I could replace most of the functions with just adding an 'i' to the function, and that I should start bughunting.

但是我的网站非常大而且庞大,要检查一切是否正常将花费很长时间.那么:对于一个非常大的网站,从MySQL切换到MySQLi的最佳方法是什么?

But my website is very complex and large, and it would take a very long time to check if everything works. So: what is the best way to switch from MySQL to MySQLi for a very large website?

谢谢!

推荐答案

对您的问题没有简单的答案,因为实际上每种简单的方法都需要在编写应用程序时以不同的方式做事.

There is no easy answer to your question as practically every simple way to do this involved doing things differently when the application was written.

如果在整个代码中都直接调用mysql_ *函数,而没有通过助手类或函数进行查询的数据库抽象层,则需要编辑每个命令.

If you have direct calls to mysql_* functions throughout your code and no database abstraction layer where you do your queries through a helper class or function then you will need to edit every command.

您不能随便在程序中添加i到mysql_query之类,因为mysqli_query()要求第一个参数是到db的链接,如果使用mysql_query()则完全是连接,这是第二个参数

You cannot just get away with adding an i to commands like mysql_query as procedurally mysqli_query() requires the first parameter to be the link to the db where with mysql_query() if a connection was given at all, it was a second parameter.

我建议不要再有更好的时间来放置数据库抽象层了,而不仅仅是将mysql_query(...)更改为mysqli_query($ link,.....).因此,请使用实际处理查询的函数(例如sql_query()),以便将来在需要再次更改数据库的情况下,只需在一个抽象文件中更新特定于数据库的命令即可.这样,如果您编写一个包装mysqli_query的函数,则可以简单地将mysql_query()重命名为helper函数,并让helper函数担心将链接放在其中.

Instead of just changing mysql_query(...) to mysqli_query($link,.....) I would recommend that there is no better time to put a db abstraction layer in place. So use functions eg sql_query() that actually process your queries so in future if you need to change DB again you can just update the db specific commands in one abstraction file. That way if you write a function that wraps mysqli_query then you could be able to simply rename your mysql_query() to your helper function and let the helper function worry about putting the link in there.

虽然这是最简单的方法,但它不会绑定参数或准备语句,这是防止sql注入漏洞的主要因素

Whilst that is the simplest way, it will not bind parameters or prepare statements which is a major factor in preventing sql injection vulnerabilities

一旦您更改了所有这些命令,就需要测试.

Once you have changed all these commands you need to test.

如果您没有编写自动化测试,那么这可能是开始编写自动化测试的好时机.即使您需要检查每个更改是否都有效,但是如果通过自动测试进行操作,则可以避免将来遇到的麻烦.

If you have no automated tests written then this is probably a good time to start writing them. Even though you will need to check that every change has worked, if you do it by automated test then you can avoid that pain in future.

这篇关于将大型网站从MySQL切换到MySQLi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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