我对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->连接上的errorInfo(),我会得到以下数组:
array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
在你问之前,是的,$ config数组保存来自connection.json文件的正确值
事先提出可能的答案!答案 0 :(得分:0)
正如安德鲁斯指出这是一个非常好的错字