Illuminate Builder不会连接(非雄辩)

时间:2016-06-13 13:48:01

标签: php laravel laravel-5 eloquent illuminate-container

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

我可以使用查询方法,但我也想添加Builder

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

错误

尝试添加构建器时,我收到以下错误 ONLY

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

docs我看到__construct()需要连接,还需要GrammarProcessors对象,我需要这些吗?

闭包中的

$ database_config

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

composer.json

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

0 个答案:

没有答案