0

我必须将 Illuminate (Non Eloquent) 用于子系统。我不想为数据库制作超过 1000 个模型。

我可以让 Query 方法正常工作,但我还想添加Builder.

应用程序.php

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;
});

错误

在尝试添加构建器时出现以下错误:

PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 
'Unsupported driver []' in    
(...) /vendor/illuminate/database/Connectors/ConnectionFactory.php:226

文档中,我看到 __construct() 需要一个连接,但也需要一个GrammarProcessors对象,我需要那些吗?

$database_config 在闭包中

$database_config = 
(
    [driver] => mysql
    [host] => localhost
    [database] => project
    [username] => root
    [password] => 
    [charset] => utf8
    [collation] => utf8_unicode_ci
)

作曲家.json

    "illuminate/database": "^5.2",
    "illuminate/pagination": "^5.2",
    "illuminate/events": "^5.2",
    "illuminate/console": "^5.2",
4

0 回答 0