Rene Terstegen
Rene Terstegen

Reputation: 8046

Doctrine 2 configuration with MySQL

I'm busy with Doctrine2, but I can't get it to work.

Everything works fine out of the box with sqlite. But when I try to change the database in the sandbox demo to MySQL I'm getting confused. This is what I did. I created a database, changed the connectionOptions array to:

$connectionOptions = array(
    'driver' => 'pdo_mysql',
    'path' => __DIR__.'/mysql.php'
);

the 'path' entry exists and looks like this:

$connectionParams = array(
    'dbname' => 'db_test',
    'user' => 'test',
    'password' => 'p4ssw0rd',
    'host' => 'localhost',
    'driver' => 'pdo_mysql',
);

When I run the command to create the database:

 php doctrine orm:schema-tool:create

Which gives me the error:

 no database selected

Seems to be a clear message. But how can I change the databasename, cause the one specified in mysql.php (see above) does excist and should be the one it uses! I searched for it for hours, but I cannot find it anywhere.

Upvotes: 9

Views: 19319

Answers (2)

Darragh Enright
Darragh Enright

Reputation: 14136

Is this the Doctrine 2 sandbox? This worked for me:

// sandbox/bootstrap.php

$connectionOptions = array(
    'driver'   => 'pdo_mysql',
    'host'     => '127.0.0.1',
    'dbname'   => 'your_database_name',
    'user'     => 'username',
    'password' => 'password'
);

$em = EntityManager::create($connectionOptions, $config);

Upvotes: 12

Kurt Krueckeberg
Kurt Krueckeberg

Reputation: 1245

The Cookbook code is also available for download. See here for the details. Look at cli-config.php after you download it.

Upvotes: -1

Related Questions