MySQLI 连接错误显示密码

MySQLI Connect Error Shows Password

我在 opencart 上有一个网站 运行,它使用命令 Mysqli connect 连接到数据库,现在我面临的问题是如果由于某些错误它无法连接或者假设我更改了我的数据库用户的密码,我的输出显示了一个致命错误,其中还包括用于连接的密码。

我收到错误

Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'saledart_admin'@'localhost' (using password: YES) in /home2/saledart/public_html/system/database/mysqli.php on line 6

Fatal error: Uncaught exception 'ErrorException' with message 'Error: Could not make a database link (1045) Access denied for user 'saledart_admin'@'localhost' (using password: YES)' in /home2/saledart/public_html/system/database/mysqli.php:9 Stack trace:> #0 /home2/saledart/public_html/vqmod/vqcache/vq2-system_library_db.php(13): DBMySQLi->__construct('localhost', 'saledart_admin', 'SqlPassword', 'saledart_db') #1 /home2/saledart/public_html/index.php(44): DB->__construct('mysqli', 'localhost', 'saledart_admin', 'SqlPassword', 'saledart_db') #2 {main} thrown in /home2/saledart/public_html/system/database/mysqli.php on line 9

如您所见,此类错误显示了我的 sql 密码,我想知道是否有一种方法可以让我的密码因此类错误而永远不会显示。

我希望我能说清楚。

此致

PS:我可以解决这个错误,因为我已经更改了数据库用户密码,但我的意思是即使是旧密码也不应该这么容易显示。

使用 php try catch ,它的异常处理用于在发生指定错误时改变代码执行的正常流程。

try {
    $con = mysqli_connect("localhost","my_user","my_password","my_db");

    if(!$conn) {
        throw new Exception('Failed');
    }
} catch(Exception $e) {
    echo 'Server error. Please try again some time.';
    die;

}