[英]hostgator - PHP - MYSQL cannot connect
我遇到非普通情況的普通問題。 當我嘗試連接到HOSTGATOR服務器中托管的mysql服務器時,出現此錯誤:
Could not connect to database. SQLSTATE[HY000] [2000] mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file.
解決方案非常簡單,請點擊此處查看詳細信息: http ://www.phpro.org/articles/Database-Connection-Failed-Mysqlnd-Cannot-Connect-To-MySQL.html
但是... HostGator不想更改“ my.cnf”文件! 而且由於我的特權,本教程中的大多數查詢都被拒絕。
我還有其他解決方案嗎? 謝謝!
請參閱Hostgator 幫助
以下代碼使用PDO進行連接。
$DBH = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
//SELECT,INSERT queries here
}
catch(PDOException $e) {
echo "I'm sorry I'm afraid you can't do that.". $e->getMessage() ;// Remove or modify after testing
file_put_contents('PDOErrors.txt',date('[Y-m-d H:i:s]'). $e->getMessage()."\r\n", FILE_APPEND);
}
// close the connection
$DBH = null;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.