atrauzzi / laravel-doctrine

An ORM for a Framework for Web Artisans
120 stars 59 forks source link

Unsupported driver Exception #105

Open jacekjagiello opened 9 years ago

jacekjagiello commented 9 years ago

Hello again, In issue #103 I've changed DB_CONNECTION to mysql and driver for this connection to pdo_mysql. Howere, now there is some issue when I register new user using default AuthController and Doctrine driver provided by this lib. When I send POST request to localhost/auth/register to register user I got:

InvalidArgumentException in ConnectionFactory.php line 189: 
Unsupported driver [pdo_mysql]

I tried to debug, this. In ConnectionFactory class there's method

 public function createConnector(array $config)
    {
        if (!isset($config['driver'])) {
            throw new InvalidArgumentException('A driver must be specified.');
        }

        if ($this->container->bound($key = "db.connector.{$config['driver']}")) {
            return $this->container->make($key);
        }

        switch ($config['driver']) {
            case 'mysql':
                return new MySqlConnector;

            case 'pgsql':
                return new PostgresConnector;

            case 'sqlite':
                return new SQLiteConnector;

            case 'sqlsrv':
                return new SqlServerConnector;
        }

        throw new InvalidArgumentException("Unsupported driver [{$config['driver']}]");
    }

And I found that my $config['driver'] is set to pdo_mysql as expected, but as we can see there's no pdo_mysql in switch.

How to setup this driver correctly?

jacekjagiello commented 9 years ago

Note, that if I switch driver to mysql in my configuration like this:

connections' => [
        'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],
],

I've got another exception:

DBALException in DBALException.php line 95: 
The given 'driver' mysql is unknown, Doctrine currently supports only the following drivers: pdo_mysql, pdo_sqlite, pdo_pgsql, pdo_oci, oci8, ibm_db2, pdo_sqlsrv, mysqli, drizzle_pdo_mysql, sqlanywhere, sqlsrv
josenicomaia commented 9 years ago

@JacekJagiello I guess this ConnectionFactory is using connection from Laravel and not for Doctrine.

I'm afraid we have no integration with register. =/

theantichris commented 9 years ago

I'm running into this road block with using this package with Laravel 5, also.

JayWhittaker commented 9 years ago

No one got a fix for this?

mbbender commented 9 years ago

Laravel uses mysql to reference the driver and Doctrine requires the value to be pdo_mysql. Somewhere along the line it should map mysql from your laravel config into pdo_mysql before it attempts to create the Doctrine (DBAL) connection.

douma commented 9 years ago

Still getting this error when I pull dev-master.

jtallant commented 9 years ago

You can fix this without changing the code.

In config/database.php use driver mysql

In config/doctrine.php use driver pdo_mysql

config/database.php

'mysql' => [
    'driver'    => 'mysql',
    'host'      => env('DB_HOST', 'localhost'),
    'database'  => env('DB_DATABASE', 'forge'),
    'username'  => env('DB_USERNAME', 'forge'),
    'password'  => env('DB_PASSWORD', ''),
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
    'strict'    => false,
],

config/doctrine.php

# Override your laravel values here if desired.
'mysql' => [
    'driver'   => 'pdo_mysql',
    // 'host'     => env('DB_HOST', 'localhost'),
    // 'dbname'   => env('DB_DATABASE', 'forge'),
    // 'user'     => env('DB_USERNAME', 'forge'),
    // 'password' => env('DB_PASSWORD', ''),
    // 'prefix'   => ''
],