繁体   English   中英

hostgator-PHP-MYSQL无法连接

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM