PHP7连接mysql数据库报错:Call to undefined function mysql_connect()

66 2018-11-5 14:09

问题描述

系统环境是CentOS+PHP7.0+Mysql5.7+Nginx。 

运行一个数据库连接测试示例时报错:

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/wwwroot/ftp.zhuxianfei.com/e/class/connect.php:132 Stack trace: #0 /home/wwwroot/ftp.zhuxianfei.com/e/class/connect.php(120): do_dbconnect('localhost', '', 'name', 'password', 'abc') #1 /home/wwwroot/ftp.zhuxianfei.com/e/admin-ftpp/ecmsadmin.php(14): db_connect() #2 {main} thrown in /home/wwwroot/ftp.zhuxianfei.com/e/class/connect.php on line 132


解决办法

查阅资料后发现,原来是从PHP5.0开始就不推荐使用mysql_connect()函数,到了php7.0则直接废弃了该函数,替代的函数是:

mysqli_connect();