問題:
When I attempt to connect to a MySQL server from PHP, I see the following error:當我嘗試從 PHP 連接到 MySQL 服務器時,我看到以下錯誤:
Deprecated: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /path/to/filename.php on line 123已棄用:mysql 擴展已棄用,將來會被刪除:在第 123 行的 /path/to/filename.php 中使用 mysqli 或 PDO 代替
The code on the referenced line is:引用行上的代碼是:
mysql_connect($server, $username, $password);
I am certain that the arguments are correct, and this exact code has been working for years without problem.我確信這些論點是正確的,這個確切的代碼多年來一直沒有問題。 Indeed, I obtained it from a well-sourced tutorial on PHP.事實上,我是從一個關於 PHP 的資源豐富的教程中獲得的。
Why is this happening?爲什麼會這樣?
How can I fix it?我該如何解決?
I understand that it's possible to suppress deprecation errors by setting
error_reporting
inphp.ini
to excludeE_DEPRECATED
:我知道可以通過在php.ini
設置error_reporting
來排除E_DEPRECATED
來抑制棄用錯誤:error_reporting = E_ALL ^ E_DEPRECATED
What will happen if I do that?如果我這樣做會發生什麼?
解決方案:
參考一: https://en.stackoom.com/question/wVie參考二: https://stackoom.com/question/wVie