centOS下PHP无法连接mysql怎么办

PHPz
Release: 2020-06-09 10:50:43
Original
2694 people have browsed it

centOS下PHP无法连接mysql怎么办

centOS下PHP无法连接mysql怎么办?

服务器本地运行php index.php可以连接mysql,浏览器访问服务器无法连接mysql

贴上相关代码

index.php

<!--?php
    echo "hello!";
    $con=mysql_connect("localhost","usites","usites160201");
    if(!$con){
        echo "error!";
        die(&#39;Could not connect:&#39;.mysql_error());
    }
 
    echo "123";
 
?-->
Copy after login

新建一个文件info.php 写进去phpinfo(); 打印出详细信息。 先看有没有加载mysql扩展。然后再说其他的

在终端下以非root权限运行php index.php试试,以排除权限问题。顺便把php的报错全开,看看有没有被log记下来

先把报错打开,看看报什么错,看起来像是死在mysql_connect那,重新安装lamp,,现在可以了。

下次使用其他的资源, 可以试试这种写法 mysql_connect(...) or die(mysql_error());。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template