无法使用PHP-FPM连接到MySQL数据库
我最近安装了php7.4-fpm(fpm/FastCGI)。但我无法连接到MySQL数据库 我正在使用以下配置。注意我的数据库没有密码。在DB_SERVER设置中尝试了“localhost”、“127.0.0.1”、“127.0.1:3306”,但没有成功无法使用PHP-FPM连接到MySQL数据库,php,mysql,apache,Php,Mysql,Apache,我最近安装了php7.4-fpm(fpm/FastCGI)。但我无法连接到MySQL数据库 我正在使用以下配置。注意我的数据库没有密码。在DB_SERVER设置中尝试了“localhost”、“127.0.0.1”、“127.0.1:3306”,但没有成功 <?php /* Database credentials. Assuming you are running MySQL server with default setting (user 'root' with no passwor
<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
define('DB_SERVER', '127.0.0.1');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'republic');
/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
// Check connection
if($link === false){
die("Oops! Something went wrong. Please try again later.");
}
?>
使用die()可以很好地说明出了什么问题,但它不能告诉您出了什么问题。我建议使用类似try-catch的方法来查看导致连接无法通过的确切原因。另外,既然您已切换到php7.4-fpm,您是否确保禁用/启用了正确的mods?
mysqli_error()
处理将是了解问题的良好开端。哎呀!出了点问题。只是没用。谢谢MySQL安全安装之后,一切都开始工作了。