php 如何查看mysql_connect失败的原因?[duplicate]

xdnvmnnf  于 2023-02-21  发布在  PHP
关注(0)|答案(1)|浏览(127)
    • 此问题在此处已有答案**:

PDO::__construct(): Server sent charset (255) unknown to the client. Please, report to the developers(12个答案)
Why shouldn't I use mysql_* functions in PHP?(14个答案)
3小时前关门了。
我安装了Linux(Mint)和LAMP,但是

mysql_connect('localhost', 'user', 'password')

无论我怎么努力都失败了。
我花了至少6个小时才修好它。

phpinfo()

正在工作

sudo mysql -u user -p

作品

sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
Apache Full                ALLOW       Anywhere                  
3306                       ALLOW       Anywhere                  
Apache Full (v6)           ALLOW       Anywhere (v6)             
3306 (v6)                  ALLOW       Anywhere (v6

我还能尝试什么?我如何调试?我已经在谷歌上搜索了几个小时。唯一不标准的是我已经安装了php 5.6,因为我需要它,"php-v"返回:

PHP 5.6.40-30+ubuntu20.04.1+deb.sury.org+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologie
p4tfgftt

p4tfgftt1#

如果你真的需要使用mysql_connect和旧的PHP:
https://www.php.net/mysql_connect上的第一个示例显示了您如何看到错误...我不确定您在哪里度过了那6个小时:)

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error()); // MAGIC LINE
}
echo 'Connected successfully';
mysql_close($link);
?>

我和其他人的建议是(正如你问题下的评论所建议的):升级到PHP7.4,然后使用适当的PDO/Mysqli连接器

相关问题