Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is DBUtil::create_database() working?
  • I tried to do this \DBUtil::create_database('dev', 'utf8_general_ci', true);

    In db.conf:

    return array(
        'default' => array(
            'connection'  => array(
                'dsn'        => 'mysql:host=localhost;dbname=dev',
                'username'   => 'root',
                'password'   => 'password',
            ),
        ),
    );

    *username and password are correct (I use the same in phpmyadmin for all operations).

    I've got an error:

    Fuel\Core\Database_Exception [ 1049 ]:
    SQLSTATE[42000] [1049] Unknown database 'dev'
  • Hmm... I deleted 'dbname=dev' from config and it made result... Possibly, I need to configure two connections for basic use and for database create.
  • Oh, no... I change my db.conf:

    return array(
        'default'  => array(
            'type'        => 'pdo',
            'connection'  => array(
                'dsn'        => 'mysql:host=localhost;dbname=dev',
                'username'   => 'root',
                'password'   => 'password',
            ),
        ),
        'createdb' => array(
            'type'        => 'pdo',
            'connection'  => array(
                'dsn'        => 'mysql:host=localhost;',
                'username'   => 'root',
                'password'   => 'password',
            ),
        )
    );

    and call \DBUtil::create_database('dev', 'utf8_general_ci', true, 'createdb');

    It works, but I've got 'devDEFAULT' database... From where does it come f..king 'DEFAULT'?
  • Good question.

    First remark: "utf8_general_ci" is a collation, not a charset. If I use your code, I get

    Fuel\Core\Database_Exception [ 42000 ]:
    SQLSTATE[42000]: Syntax error or access violation: 1115 Unknown character set: 'utf8_general_ci' with query: "CREATE DATABASE IF NOT EXISTS `DEV`DEFAULT CHARACTER SET utf8_general_ci DEFAULT COLLATE utf8_general_ci"

    If I fix that by changing it to

    \DBUtil::create_database('dev', 'utf8', true, 'createdb');

    It creates the database "dev" here without problems. So no idea where DEFAULT comes from in your case.

  • HarroHarro
    Accepted Answer
    I do see now that `DEV` and DEFAULT don't have a space in between, so if you don't have any delimiters defined, that could become DEVDEFAULT.


    If you're using MySQL, make sure you have defined the correct delimiters in your db config:

    'identifier'   => '`',

  • Thank you, Harro. I need time to check and try, but I think it make sense.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion