MySQLI Connect Error Shows Password

空扰寡人 提交于 2019-12-11 11:52:54

问题


I have a website running on opencart which uses command Mysqli connect to connect to database, now the problem i am facing is if due to some error it is not able to connect or lets say i change the password for my database user my Output shows a fatal error which includes the password used to connect also.

Error i Receive

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

As you can see such error displays my sql password, i want to know if there is a way that my password is not shwn ever due to any error like this.

I hope i was able to make myself clear.

Regards

PS: I Can resolve this error since this is coming since i have changed the Database users password but my point is that even old password should not be shown such easily.


回答1:


use php try catch , its Exception handling is used to change the normal flow of the code execution if a specified error occurs.

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;

}


来源:https://stackoverflow.com/questions/28591394/mysqli-connect-error-shows-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!