XAMPP-致命错误:调用未定义函数mysql_connect() [英] XAMPP - Fatal error: Call to undefined function mysql_connect()
问题描述
我下载了XAMPP下载用于我的学习课程.我完成后 安装,我可以正常使用.但是当我尝试连接到MySQL时,我总是返回此错误.
I downloaded downloading XAMPP for my learning lesson. After I finished the install, I can use it normally. But when I try to connect to MySQL I keep return this error.
<?php
define("DB_HOST","localhost");
define("DB_USER","root");
define("DB_PWD","");
define("DB_DBNAME","text");
define("DB_CHARSET","utf8");
?>
function connect(){
$link=mysql_connect("DB_HOST","DB_USER","DB_PWD") or die("连接失败Error:".mysql_error().":".mysql_error());
mysql_select_db(DB_DBNAME);
return $link;
}
推荐答案
首先,请确保MySQL服务正在运行.
First, Kindly ensure the MySQL service is running.
- 打开XAMPP控制面板
- 单击与MySQL模块相对应的开始"按钮.
然后,尝试检查是否正在加载PHP MySQL扩展模块:
Then, Try checking to see if the PHP MySQL extension module is being loaded:
<?php
phpinfo();
?>
运行上面的代码/页面并搜索mysql. 如果不存在,请将以下内容添加到php.ini文件中:
Run the above code/page and search for mysql. If it's not there, add the following to the php.ini file:
extension=php_mysql.dll
更新:PHP 7中已删除mysql_ *函数.XAMPP中可能有一个php7.请使用PDO或mysqli_connect("DB_HOST","DB_USER","DB_PWD")
代替mysql_connect().
Update: mysql_* functions have been removed in PHP 7. You probably have a php7 in XAMPP. Please use PDO or mysqli_connect("DB_HOST","DB_USER","DB_PWD")
instead of mysql_connect().
这篇关于XAMPP-致命错误:调用未定义函数mysql_connect()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!