开发者

Uncaught Exception 'PDOException' with message 'SQLSTATE[HY000] [2003] Can't connect to MySQL server

I am using Zend Framework and my application works on localhost but produces the can't connect to MySQL server error when I'm trying to connect to the database I've uploaded on a live server. I've tried handling exceptions and Zend_Exception catches it("perhaps factory() failed to load the specified Adapter class"). I've emailed the webmaster and he told me that Phpmyadmin is working fine so there should be no problem with connecting php to mysql. What else can I do? The lines that produce the error are the following:

    $db = Zend_Registry::get('db');
    $sql = 'SELECT * FROM department';
    $result = $db->fetchAll($sql);  

Is there something specific I can ask the webmaster to look at?

EDIT:

in my bootstrap:

public function _initDB()
{   

    $dbOptions = $this->getOption('db');
    $db = Zend_Db::factory($dbOptions['adapter'], $dbOptions['params']);
    Zend_Registry::set('db', $db);
    Zend_Db_Table_Abstract::setDefaultAdapter($db);
}

in my application.ini:

db.adapter = PDO_MYSQL
db.params.host = agila.upm.edu.ph
db.params.username = FacultyDB 
db.params.password = *********
db.params.dbname = F开发者_如何学GoacultyDB


Since you are convinced the settings are ok in application.ini are you initialising your db in bootstrap?

protected function _initDb() {

    $registry = Zend_Registry::getInstance();

    $db = Zend_Db::factory($registry->config->db->adapter,
                    $registry->config->db->database->toArray());

    Zend_Db_Table::setDefaultAdapter($db);
    Zend_Registry::set('db', $db);
}

try that in application.ini:

[db]
adapter = PDO_MYSQL
database.host = agila.upm.edu.ph
database.username = FacultyDB 
database.password = *********
database.dbname = FacultyDB 

Try configuring with that and my bootstrap code and see if it now works. I remember something about zend_db being picky about configuration from application.ini. I could be wrong its vague.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜