“调用未定义函数 mysql_connect()"升级到 php-7 后
将 php5 升级到 php7 后,我收到错误 500
After I upgraded php5 to php7, I get an error 500 with
PHP 致命错误:未捕获错误:调用未定义函数 mysql_connect()
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect()
我把它放到我的 apt 资源中,以便立即获得 php7:
I put this into my apt sources in order to get php7 right now:
deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all
deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all
我基本上做的是:
apt-get remove php5
apt-get install php7-*
我正在使用当前版本的 Debian Jessie.
但我仍然明白这一点.这里有很多关于 SO 的问题,我肯定都检查过了.但我还没有找到答案.
But I still get this. There are a lot of questions here on SO and I definitely checked them all out. But I didn't find an answer there yet.
推荐答案
来自 PHP手册:
警告 此扩展在 PHP 5.5.0 中已弃用,并已被删除在 PHP 7.0.0 中.相反,MySQLi 或 PDO_MySQL 扩展名应该是用过的.另请参阅 MySQL:选择 API 指南.此功能的替代方案包括:
Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide. Alternatives to this function include:
mysqli_connect()
PDO::__construct()
使用 MySQLi
或 PDO
<?php
$con = mysqli_connect('localhost', 'username', 'password', 'database');
相关文章