-1
我正在写一个数据库类,它将连接到我的pdo数据库。这个类是使用这个配置文件,以获得所需的信息:无法连接到php数据库与pdo
<?php
return [
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
'database_name' => 'books',
'database_type' => 'mysql',
'options' => []
];
这是数据库类:
<?php
class DB
{
public static function connect($config)
{
try {
return new PDO([
$config['database_type'] . ':host=' . $config['host'] . ';dbname=' . $config['database_name'],
$config['username'],
$config['password'],
$config['options']
]);
} catch(PDOException $e) {
die($e->getMessage());
}
}
}
我收到此错误:
Fatal error: Uncaught TypeError: PDO::__construct() expects parameter 1 to be string, array given in and etc...
我想知道我做错了什么,我没有看到我的代码中有任何语法错误。
你是对的。完全是我的不好。甚至没有注意到它。谢谢! –