問題描述
根據 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 擴展的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!