我正在尝试使用通过Zend的PDO连接连接到数据库:
<?php
class Feuerwehr_Db extends Zend_Db {
public static function factoryEinsaetze(){
$config = array(
'LOCAL' => array(
'servername' => "localhost",
'username' => "root",
'password' => "admin",
'dbname' => "einsaetze"
),
'LIVE' => array(
'servername' => "rdbms.strato.de",
'username' => "U2340080",
'password' => "*****",
'dbname' => "DB2340080"
)
);
return parent::factory('Pdo_Mysql', $config[Feuerwehr_Environment::getStage()]);
}
}
Connection正确选择所有登录数据并创建数据库连接。一切都在本地工作正常,但在我的Strato服务器上,Connection失败,但有以下异常:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' in /mnt/web024/d1/57/5707957/htdocs/Beta/library/Zend/Db/Adapter/Pdo/Abstract.php:129 Stack trace: #0 /mnt/web024/d1/57/5707957/htdocs/Beta/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('mysql:servernam...', 'U2340080', '*****', Array) #1.....
服务器上的PHP版本为5.6,标准的mysql_connect工作正常。
答案 0 :(得分:0)
Zend期望密钥“host”而不是“servername”。默认参数设置为localhost,它解释了错误异常。