0

我对 PDO 有一个非常奇怪的问题。它不断告诉我:

SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected

有问题的代码:

settings.json 文件:

"connection" : {
    "handler" : "Meagl\\Core\\Connection\\SimplePdoMySql",
    "settings" : {
        "driver" : "mysql",
        "dsn" : "mysql:host=localhost;dbame=meagl",
        "username" : "meagl",
        "password" : "meagl"
    }
}

创建连接的 SimplePdoMysql 适配器构造函数:

class SimplePdoMySql extends \Meagl\Core\Connection\SimplePdo {

    /**
     * Try and connect to the Database using PDO
     */
    public function __construct($config) {
        $this->connection = new \Pdo($config['dsn'], $config['username'], $config['password']);
        $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
    }

产生错误的函数:

protected function selectAllResourceIdentifiers() {
    $sth = $this->connection->query("SHOW TABLES");
    return $sth->fetchAll(\PDO::FETCH_COLUMN,0);
}

如果我检查 $this->connection 上的 errorInfo(),我会得到以下数组:

array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }

在你问之前,是的,$config 数组保存了 connection.json 文件中的正确值

提前谢谢可能的答案!

4

1 回答 1

0

正如 andrewsi 指出的那样,这是一个非常好的错字

于 2013-08-29T15:22:01.530 回答