4,251
社区成员
发帖
与我相关
我的任务
分享
<?php
$link=mysqli_connect('localhost','root','Ali123_123');
if(!$link){
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errorno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() .PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made!" . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
?>
[root@iZm5ej6knwmfwy1312s25dZ ~]# curl -v localhost
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 03 Sep 2020 04:47:32 GMT
< Server: Apache/2.4.6 (CentOS) PHP/7.2.33
< X-Powered-By: PHP/7.2.33
< Content-Length: 179
< Content-Type: text/html; charset=UTF-8
<
Error: Unable to connect to MySQL.
Debugging errorno: 2002
Debugging error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
PHP_Sapi_Name: apache2handler
* Connection #0 to host localhost left intact
[root@iZm5ej6knwmfwy1312s25dZ ~]# php /var/www/html/index.php
Success: A proper connection to MySQL was made!
Host information: Localhost via UNIX socket
PHP_Sapi_Name: cli
发现另一个是apache2handler,这里会不会存在什么问题。
另文件的权限:-rw-r--r-- 1 root root 578 9月 3 12:47 /var/www/html/index.php
srwxrwxrwx 1 mysql mysql 0 9月 2 09:33 /tmp/mysql.sock