IIS服务器配置php网站,数据库连接用户名错乱

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mzc186/article/details/88531171

这两天配置一个IIS服务器上的网站,遇到了一个诡异的问题。具体情况描述如下:

<?php
 $mysql_conf = array(
    'host'    => 'localhost', 
    'db'      => 'test', 
    'db_user' => 'test', 
    'db_pwd'  => '123456', 
    );
$mysql_conn = @mysql_connect($mysql_conf['host'], $mysql_conf['db_user'], $mysql_conf['db_pwd']);
if (!$mysql_conn) {
    die("could not connect to the database:\n" . mysql_error());//诊断连接错误
} else{
	echo 'connect to database succefully!';
}

?>

用这段代码测试连接数据库,在mysql控制台用test用户和上述对应的123456密码登陆数据库没有问题,但是用http访问该php文件,浏览器输出如下的错误信息:

could not connect to the database: Access denied for user ‘IUSR’@‘localhost’ (using password: NO)

数据库打印的调试信息显示,当前连接的数据库用户居然会是’IUSR@localhost’,前思后想怎么都想不通,多次尝试无果后咨询了云服务器管理的技术支持,他帮换了一个php版本问题就解决了。从php5.6切换到php5.3。

当时没往这方面想,这样的信息提示和php版本没有联想到一起。之前一直以为是IIS网站访问用户的权限问题。这提示信息感觉挺诡异的 ~

猜你喜欢

转载自blog.csdn.net/mzc186/article/details/88531171