PHP 5.5.x 中已弃用的 MySQL 扩展

时间:2023-03-05
本文介绍了PHP 5.5.x 中已弃用的 MySQL 扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

根据 PHP 手册,以及自 PHP 5.5 起互联网上的大量资源.x 不推荐使用整个原始 MySQL 扩展.我有一个非常强大的 Web 应用程序,我的协会中的很多学生都在使用它,但是当我对 PHP 一无所知时我开始研究它,而且我从来没有费心将 MySQL_* 扩展名更改为 MySQLi_* 或 PDO_MySQL.

According to the PHP manual, and a lot of sources on the internet as of PHP 5.5.x the whole original MySQL extension is deprecated. I have a really robust web application that is used by a lot of students in my association, but I started working on it when I didn't know a lot of PHP and I never bothered with changing the MySQL_* extension with MySQLi_* or PDO_MySQL.

Web 应用程序已完成,所有系统都在运行,并且可能不会通过新功能进行增强,所以我的问题是:我是否应该花一些时间更改所有 mysql_* 调用并使用 mysqli_* 调用切换它们.如果我将所有内容都保留在已弃用的 mysql_* 扩展名中,我的应用程序是否会在 Internet 上无法访问?

The web app is finished and all systems are running and will probably not be enhanced with new features, so my question is: Should I take some time and change all the mysql_* calls and switch them with mysqli_* calls. Is my application ever going to become inaccessible on the internet if I leave everything with the deprecated mysql_* extension?

推荐答案

如果我将所有内容都保留在已弃用的 mysql_* 扩展名中,我的应用程序是否会在 Internet 上无法访问?

Is my application ever going to become inaccessible on the internet if I leave everything with the deprecated mysql_* extension?

您的应用程序只有在运行它的服务器升级到不支持旧 API 的 PHP 版本时才会中断.如果您的服务器没有升级到 PHP 5.5,那么您的应用程序将无限期地继续运行.在这方面,外部互联网上的任何其他内容都不会对其产生影响;只有升级到您自己的服务器才是相关的.

Your application will only break if and when the server it is running on is upgraded to a PHP version that doesn't support the old API. If your server doesn't get upgraded to PHP 5.5, then your app will continue running as is indefinitely. Nothing else on the outside internet will affect it in that respect; only upgrades to your own server are relevant.

目前,php 5.4 仍处于积极支持状态,因此您可以愉快地继续使用该版本,而无需担心您的代码突然中断.

For the time being, php 5.4 is still actively supported, so you can happily stay on that version without needing to worry about your code suddenly breaking.

但是,在未来的某个时候,出于某种原因,您需要升级到 PHP 5.5 或更高版本.PHP 5.4 将停止使用,建议迁移到 5.5.或者,如果您使用的是共享主机帐户,您甚至可能无法选择 PHP 版本.所以是的,您应该期望您当前的代码不能与您当时使用的 PHP 版本一起使用.最终.

However, at some point in the future, for one reason or another, you will need to upgrade to PHP 5.5 or higher. PHP 5.4 will become end-of-life, and a move to 5.5 will be recommended. Or if you're using a shared hosting account, you may not even have any choice over your PHP version. So yes, you should expect for your current code not to work with the PHP version you're using at the time. Eventually.

因此,虽然没有立即进行转换的紧迫性,但您应该考虑尽快进行转换.你想要的一件事是,在事情破裂的那一天到来时,发现自己陷入困境.

So while there's no immediate urgency to make the switch, you should consider doing so as soon as possible. One thing you don't want is for the day to come when things break, and find yourself caught out.

5.5 才刚刚发布,所以你可能需要几年时间才能让它成为可用的最低版本,但请听我的建议;你不想等到最后一刻.

5.5 has only just been released, so you probably have a few years before it becomes the lowest version available, but take my advice; you don't want to wait till the last moment.

我是否应该花一些时间更改所有 mysql_* 调用并使用 mysqli_* 调用切换它们.

Should I take some time and change all the mysql_* calls and switch them with mysqli_* calls.

您表示您的应用非常强大"并且可能不会得到增强".所以基本上处于长期只维护阶段.

You stated that your app is "really robust" and "will probably not be enhanced". So it's basically in a long-term maintenance-only phase.

鉴于这些标准,我会说是的,简单地切换到 mysqli 库是一个明智的举动.所需的更改相当微不足道(听起来您已经掌握了要做什么),并且几乎不会对软件的其余部分产生任何影响.

Given those criteria, I would say that yes, making a simple switch to the mysqli lib is a sensible move. The changes required are fairly trivial (it sounds like you've got a handle on what to do already), and should have virtually no impact whatsoever on the rest of the software.

如果您的代码确实健壮且编写得很好,那么您将对其进行结构化,以便有某种类型的数据库层,这意味着您无论如何都无事可做.

If your code is truly robust and well-written, you'll have it structured in such that there is a database layer of some sort, which will mean that you don't have much to do anyway.

如果它的结构不是很好,它可能会有很多 mysql_query() 调用分散在代码中,在这种情况下,它可能需要更多的工作.在这种情况下,由于您无论如何都在处理代码,您可能会考虑花时间进行一些重组.创建数据库层.也许开始使用准备好的语句.我还建议切换到 PDO 而不是 mysqli.但是你的呼吁——鉴于你在问题中所说的,如果你想做尽可能少的工作,这是可以理解的.

If it's not so well structured, it might have a lot of mysql_query() calls scattered around the code, in which case it might take a bit more work. In this case, since you're working on the code anyway, you might consider taking the time to do a bit of restructuring. Create a database layer. Maybe start using prepared statements. I'd also recommend switching to PDO rather than mysqli. But your call -- given what you said in the question, it would be understandable if you wanted to do the minimum amount of work possible.

顺便说一句 - 如果您还没有这样做,您可能还想阅读以下内容:为什么我不应该在 PHP 中使用 mysql_* 函数?

By the way - If you haven't done so already, you might also want to read this: Why shouldn't I use mysql_* functions in PHP?

这篇关于PHP 5.5.x 中已弃用的 MySQL 扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:不能在 mysqli_stmt 对象上使用 call_user_func_array 下一篇:MySQLi 更新的增量值

相关文章