学习PHP中的。今天学习php链接数据库,代码以下:php
<?php $link = mysql_connect("127.0.0.1","root","123456"); if($link) { echo '数据源链接成功'; } else { echo "数据库链接失败,请检查账户密码". mysql_error().mysql_errno(); } ?>
本地测试正常能够访问html
php /var/www/html/conndb.phpmysql
<html> <head> <meta charset="UTF-8"> <title></title> </head> <body> 鏁版嵁婧愯繛鎺ユ垚鍔 </body> </html>
windows机器使用IE没法访问,报错以下:linux
Can't connect to MySQL server on '127.0.0.1' (13)2003web
问题点:防火墙与selinuxsql
临时解决方法:数据库
service iptables stop #中止iptablesvim
setenforce 1 #临时关闭Selinuxwindows
永久方法ide
chkconfig --leve 12345 iptables off
vim /etc/selinux/config
第7行的:SELINUX= enforcing
修改:SELINUX= disabled
重启机器:reboot
[root@web-php ~]# sestatus -v
SELinux status: disabled