PHP连接数据库错误:Can't connect to MySQL server on '127.0.0.1' (13)2003

时间:2015-12-22 06:47:51   收藏:0   阅读:668

学习PHP中的。今天学习php连接数据库,代码如下:

   <?php
      $link = mysql_connect("127.0.0.1","root","123456");
        if($link) {
            echo ‘数据源连接成功‘;
        }
        else {
            echo "数据库连接失败,请检查帐户密码".  mysql_error().mysql_errno();
        }
     
        ?>

本地测试正常可以访问

php /var/www/html/conndb.php

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        鏁版嵁婧愯繛鎺ユ垚鍔   </body>
</html>

windows机器使用IE无法访问,报错如下:

Can‘t connect to MySQL server on ‘127.0.0.1‘ (13)2003

问题点:防火墙与selinux

临时解决方法:

service iptables stop  #停止iptables

setenforce 1              #临时关闭Selinux

永久方法

 chkconfig --leve 12345 iptables off

vim /etc/selinux/config

第7行的:SELINUX= enforcing

修改:SELINUX= disabled

重启机器:reboot

[root@web-php ~]# sestatus -v
SELinux status:                 disabled

技术分享



本文出自 “Fly High into the Sky” 博客,请务必保留此出处http://xjlsky.blog.51cto.com/22754/1726811

原文:http://xjlsky.blog.51cto.com/22754/1726811

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!