0

I have to use the Illuminate (Non Eloquent) for a sub-system. I don't want to make over 1000 models for the Database.

I can get the Query methods working but I'd also like to add the 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;
});

The Error

I get the following error ONLY when trying to add the builder:

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

In the docs I see the __construct() requires a connection but also a Grammar and Processors object, do I need those?

$database_config in the closure

$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",
JREAM
  • 5,741
  • 11
  • 46
  • 84
  • Have you considered using a package for auto-generating models from the database? For example: https://github.com/ignasbernotas/laravel-model-generator – henrik Jun 13 '16 at 14:01
  • That's a really strange looking `app.php` file. Why not let Laravel wire up your DB just as if you were using Eloquent. You can still avoid creating models, and run `DB::raw` queries. Or you could pull out the underlying DB connection that Laravel wires up, and use it on your own. – jszobody Jun 13 '16 at 14:15
  • @jszobody I am not using Laravel, only the Illuminate database. Can I run $db->select() $db->insert() etc when loading Eloquent? – JREAM Jun 13 '16 at 16:26
  • @henrik I would but, 1000+ tables is insanity, half of which I don't even think are even used LOL. I don't know what goes where, it's quite wild. – JREAM Jun 13 '16 at 16:26

0 Answers0