解决The mysql extension is deprecated and will be removed
2017-12-07 22:02:53
今天在看网站日志的时候,发现有很多这样的信息“PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in”。

翻译了一下,大概意思就是mysql_connect()这个mysql扩展已废弃,在以后可能会将其删除。建议使用mysqli或pdo。

但是为什么以前就好好的呢?

这是因为php版本不同,新版本的就会有这样的提示。

解决方法有三种。

方法一
display_errors = On
改为

display_errors = Off
禁止php报错,但是这样很明显是不明智的做法,因为如果哪里出错了,我们自己都不知道。

方法二
在php程序中,添加如下代码。

error_reporting(E_ALL ^ E_DEPRECATED);
不过也不建议使用,最好是使用方法三,因为mysql实在是太不安全、太老旧了。

方法三
将mysql改为mysqli,你可能会觉得要改的很多,其实并不多,一般的只需改mysql.class.php文件就可以了。

比如说将

mysql_connect($server, $username, $password)
改为

mysqli_connect($server, $username, $password,$database)
即可。

很多地方都是一样的,只需将将“mysql”改为“mysqli”就能解决。

本文网址:http://www.santii.com/article/172.html

Last modification:April 21, 2020
如果觉得我的文章对你有用,请随意赞赏