gpt4 book ai didi

php - PDO不会选择数据库

转载 作者:行者123 更新时间:2023-11-30 01:21:12 25 4
gpt4 key购买 nike

我在 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 文件中的正确值

提前感谢可能的答案!

最佳答案

正如安德鲁西指出的那样,这是一个非常恰当的拼写错误

关于php - PDO不会选择数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18514850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com