升级到 php-7 后“调用未定义的函数 mysql_connect()”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34088373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Call to undefined function mysql_connect()" after upgrade to php-7
提问by bytecode77
After I upgraded php5to php7, I get an error 500 with
将php5升级到php7 后,出现错误 500
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect()
PHP 致命错误:未捕获的错误:调用未定义的函数 mysql_connect()
I put this into my apt sources in order to get php7 right now:
我把它放到我的 apt 源中,以便立即获得 php7:
deb http://packages.dotdeb.orgjessie all
deb-src http://packages.dotdeb.orgjessie all
deb http://packages.dotdeb.orgjessie all
deb-src http://packages.dotdeb.orgjessie all
What I basically did is:
我基本上做的是:
apt-get remove php5
apt-get install php7-*
I'm using the current version of Debian Jessie.
我正在使用当前版本的 Debian Jessie。
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.
但我仍然明白这一点。这里有很多关于 SO 的问题,我肯定把它们都查了一遍。但我还没有在那里找到答案。
回答by Abhishek Sharma
From the PHP Manual:
从PHP 手册:
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:
警告 此扩展在 PHP 5.5.0 中已弃用,并在 PHP 7.0.0 中删除。相反,应使用 MySQLi 或 PDO_MySQL 扩展。另请参阅 MySQL:选择 API 指南。此功能的替代方案包括:
mysqli_connect()
PDO::__construct()
use MySQLi
or PDO
使用MySQLi
或PDO
<?php
$con = mysqli_connect('localhost', 'username', 'password', 'database');