Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Oil version 1.4 no database error when migrating and create user via oil console
  • Hi, i'm trying to build new application with fuel 1.4. When i try to migrate with oil, there is an error message "No Database Selected". This also happen when I try to create user via oil command line. I have set the database config in /fuel/app/config/development and already make the database. Is there something I've missed, or this is a bug?? +
  • Check to make sure the commandline version of PHP uses the same php.ini as your webserver.

    If you're using something like MAMP or WAMP, this is often the issue, causing the database drivers not to be loaded.

  • Hi, I have solved this problem. Here is the "log" of what I have done.

    1. When I create a new app via command line using oil create /mysite in /var/www, it was a success.
    2. But when I navigate to localhost/mysite/public/index.php, I redirected to an 404 page.
    3. So I go to /fuel/core/config and fill the 'index_file' with 'index.php'.
    4. I refreshed the page and it worked.
    5. When I using oil to generate a model 

    oil g model users username:varchar[50] password:string group:int email:string last_login:int login_hash:string profile_fields:text

    6. An error occured

    Error - Class 'Clio' not found in PKGPATH/oil/classes/generate.php on line 238

    7. I change the 'Clio' to 'Cli' at line 238 and tried again to generate a model, and it was success
    8. Now trying to migrate using oil refine migrate, but an error occured

    1046 - No database selected [ CREATE TABLE IF NOT EXISTS `migration` (
    `type` varchar(25) NOT NULL,
    `name` varchar(50) NOT NULL,
    `migration` varchar(100) DEFAULT '' NOT NULL
    ) DEFAULT CHARACTER SET utf8; ] in COREPATH/classes/database/mysqli/connection.php on line 243

    9. I fill the parameter of msqli config at /fuel/core/config/db
    10. I tried to run the migrate once again, and it was a success
    11. I use the oil console to create a user and it was success

    By the way, I didn't have to fill the mysqli config when I use FuelPHP 1.3 to define the database. Just change the 'dbname' at /fuel/app/config/development/db and it all worked just fine. +
  • You should not modify config/db.php, unless you're changing global parameters. Anything in development will overwrite what you have defined globally. Both are by default configured for PDO, not for MySQLi, so you have changed more then only the db name. Maybe you should post both config files here (remove the password) so we can have a look.

    Absolutely nothing has changed in 1.4 compared to 1.3.
  • Yes, Harro, I know that I shouldn't modify anything in config/db. I'm just trying to solve the problem.

    Here is my fuel/app/config/development/db

    <?php
    /**
     * The development database settings. These get merged with the global settings.
     */

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

    Here is the fuel/app/config/db

    <?php
    /**
     * Use this file to override global defaults.
     *
     * See the individual environment DB configs for specific config information.
     */

    return array(

    );
     
    And here is my fuel/core/config/db

    /**
    * Base MySQLi config
    */
    'default' => array(
    'type'        => 'mysqli',
    'connection'  => array(
    'hostname'   => 'localhost',
    'username'   => 'root',
    'password'   => 'mypassword',
    'database'   => 'sic_perpus',
    'persistent' => false,
    ),
    'identifier'   => '`',
    'table_prefix' => '',
    'charset'      => 'utf8',
    'enable_cache' => true,
    'profiling'    => false,
    ),

    I just modify that setting, nothing else. In FuelPHP version 1.3, the db.php file inside fuel/app/config/ is not empty, there lies the PDO type connection setting. Should I fill this with the setting like in version 1.3?? +
  • As I said in my previous post, absolutely nothing has changed in 1.4 compared to 1.3.

    The issue I think here is that development/db is merged with db, and the development data has precedence.

    Can you do

    \Config::load('db', true);
    \Debug::dump(\Config::get('db');


    and check if it contains what you expect?
  • This is the result using \Config::load('db', true);

    findrakecil@Inspiron-1012:/var/www/sic_dev$ oil console
    Fuel 1.4 - PHP 5.3.10-1ubuntu3.4 (cli) (Sep 12 2012 18:59:31) [Linux]
    >>> Config::load('db', true)
    array (
      'active' => 'default',
      'default' => 
      array (
        'type' => 'mysqli',
        'connection' => 
        array (
          'hostname' => '',
          'username' => 'root',
          'password' => 'keong',
          'database' => '',
          'persistent' => false,
          'dsn' => 'mysql:host=localhost;dbname=sic_perpus',
        ),
        'identifier' => '`',
        'table_prefix' => '',
        'charset' => 'utf8',
        'enable_cache' => true,
        'profiling' => false,
      ),
      'redis' => 
      array (
        'default' => 
        array (
          'hostname' => '127.0.0.1',
          'port' => 6379,
          'timeout' => NULL,
        ),
      ),
    )

    And this is the result of Debug::dump(Config::get('db'))

    >>> Debug::dump(Config::get('db'))
    array(3) {
      ["active"]=>
      string(7) "default"
      ["default"]=>
      array(7) {
        ["type"]=>
        string(6) "mysqli"
        ["connection"]=>
        array(6) {
          ["hostname"]=>
          string(0) ""
          ["username"]=>
          string(4) "root"
          ["password"]=>
          string(5) "keong"
          ["database"]=>
          string(0) ""
          ["persistent"]=>
          bool(false)
          ["dsn"]=>
          string(38) "mysql:host=localhost;dbname=sic_perpus"
        }
        ["identifier"]=>
        string(1) "`"
        ["table_prefix"]=>
        string(0) ""
        ["charset"]=>
        string(4) "utf8"
        ["enable_cache"]=>
        bool(true)
        ["profiling"]=>
        bool(false)
      }
      ["redis"]=>
      array(1) {
        ["default"]=>
        array(3) {
          ["hostname"]=>
          string(9) "127.0.0.1"
          ["port"]=>
          int(6379)
          ["timeout"]=>
          NULL
        }
      }
    }

    That's it. Hope it can help +
  • You defined the 'mysqli' driver, which requires separate user, pass, host, port and dbname. Only the PDO driver uses the 'dsn' value.

    So either switch the driver to PDO, or define the correct fields.
  • Oops.

    Issue seems to be related to the default db.php file in fuel/core/config, which has two default entries for both PDO and MySQLi, the last one overwriting the first one.

    Remove the MySQLi entry in there to fix the issue.
  • Thank you Harro, this problem is solved :) +

Howdy, Stranger!

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

In this Discussion