我试着连接到这样一个遥远的主机:
class Singleton {
public static $connection;
public static function getConnection(){
if(self::$connection==null){
$dsn = 'mysql:dbname=gtrscrpt_ubot;';
$user = 'MyUser';
$password = 'MyPassword';
try {
self::$connection = new PDO('mysql:host=gator188.hostgator.com;port=2983;dbname=gtrscpt_ubot;',$user,$password );
self::$connection->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
}
return self::$connection;
}
}
Singleton::getConnection();我明白了:
Connection failed: SQLSTATE[HY000] [2006] MySQL server has gone away问题是我不知道我的代码是错的还是不能连接到服务器(但是我知道我应该连接)
更新:连接失败: SQLSTATEHY000 mysqlnd无法使用旧的不安全身份验证连接到MySQL 4.1+。请使用管理工具用命令集密码=密码(‘your_existing_password’)重置密码。这将在mysql.user中存储一个新的、更安全的哈希值。如果在PHP5.2或更早版本执行的其他脚本中使用此用户,则可能需要从my.cnf文件**中删除旧密码标志。
发布于 2012-11-28 10:30:27
https://stackoverflow.com/questions/13602779
复制相似问题