gpt4 book ai didi

php - hostgator - PHP - MYSQL 无法连接

转载 作者:行者123 更新时间:2023-11-30 01:03:19 24 4
gpt4 key购买 nike

我在非常见情况下遇到了常见问题。当我尝试连接到 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 help

以下代码使用 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;
?>

关于php - hostgator - PHP - MYSQL 无法连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19904772/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com