
服务器本地运行php index.php可以连接mysql,浏览器访问服务器无法连接mysql
贴上相关代码
index.php
<!--?php
echo "hello!";
$con=mysql_connect("localhost","usites","usites160201");
if(!$con){
echo "error!";
die('Could not connect:'.mysql_error());
}
echo "123";
?-->新建一个文件info.php 写进去phpinfo(); 打印出详细信息。 先看有没有加载mysql扩展。然后再说其他的
立即学习“PHP免费学习笔记(深入)”;
在终端下以非root权限运行php index.php试试,以排除权限问题。顺便把php的报错全开,看看有没有被log记下来
先把报错打开,看看报什么错,看起来像是死在mysql_connect那,重新安装lamp,,现在可以了。
下次使用其他的资源, 可以试试这种写法 mysql_connect(...) or die(mysql_error());。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号