学习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

wKiom1Z3pKiSshQAAACVY3kLUjI675.jpg