我必须使用Illuminate(非Eloquent)作为子系统。我不想为数据库制作超过1000个模型。
我可以使用查询方法,但我也想添加Builder
。
use \Illuminate\Database\Capsule\Manager as Capsule;
use \Illuminate\Database\Query\Builder;
use \SuperClosure\SerializableClosure;
use \Pimple\Container;
$container = new Container();
$container['db'] = new SerializableClosure(function() use ($database_config) {
print_r($database_config);
$capsule = new Capsule;
$capsule->addConnection([
'driver' => $database_config['driver'],
'host' => $database_config['host'],
'database' => $database_config['database'],
'username' => $database_config['username'],
'password' => $database_config['password'],
'charset' => $database_config['charset'],
'collation' => $database_config['collation'],
]);
$capsule->setFetchMode(\PDO::FETCH_OBJ);
// Re-use the connection if needed
$connection = $capsule->getConnection();
// I want to Attach this so I can have access in one DI call.
$capsule->builder = new Builder($connection);
return $connection;
});
尝试添加构建器时,我收到以下错误 ONLY :
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message
'Unsupported driver []' in
(...) /vendor/illuminate/database/Connectors/ConnectionFactory.php:226
在docs我看到__construct()需要连接,还需要Grammar
和Processors
对象,我需要这些吗?
$database_config =
(
[driver] => mysql
[host] => localhost
[database] => project
[username] => root
[password] =>
[charset] => utf8
[collation] => utf8_unicode_ci
)
"illuminate/database": "^5.2",
"illuminate/pagination": "^5.2",
"illuminate/events": "^5.2",
"illuminate/console": "^5.2",