Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database selection
  • Hi All! In my root htaccess file I've set the environmental variable to development as below.
    SetEnv FUEL_ENV development
    

    Then updated the database settings to /config/development/db.php Now, when I try to query using the Db class it's looking into the /config/db.php instead of /config/development/db.php Have I missed any step? Also, just wondering how you put environmental specific variables in the config.php file. Many thanks.
  • The generic config file (config/db.php) and the environment file (config/your_environment/db.php) are merged by the Config class when loaded. If the result is not what you expect, maybe the environment selection failed. Dump \Config::get('db') to see what was loaded, you can add a dummy value to your environment db.php to add the debugging process.
  • Hi WanWizard! Thanks for your quick response. Dumping \Config::get('db') shows nothing. Echoing echo Fuel::$env; in bootstrap.php is showing "development" When i'm calling
    DB::list_tables();
    
    from the controller I'm getting this error message:
    Fuel\Core\FuelException [ Error ]: Database method Fuel\Core\Database_PDO_Connection::list_tables is not supported by Fuel\Core\Database_PDO_Connection
    

    If I remove the default PDO settings from db.config I get error below:
    Fuel\Core\FuelException [ Error ]: Database type not defined in default configuration
    

    Harro Verton wrote on Monday 19th of March 2012:
    The generic config file (config/db.php) and the environment file (config/your_environment/db.php) are merged by the Config class when loaded. If the result is not what you expect, maybe the environment selection failed. Dump \Config::get('db') to see what was loaded, you can add a dummy value to your environment db.php to add the debugging process.
  • If you're on 1.1/master (the release), that error message is correct, as PDO does not support list_tables() and list_columns(). This has nothing to do with environments. In 1.1/develop, for the list_columns() method a workaround is implemented, but list_tables() is still not supported. The db config is only loaded at the first db call, so it is possible that when you dump it it isn't loaded yet.
  • I'm trying to use mysql driver not PDO but it's getting picked up by default. I was hoping by setting the environmental variable to development it will pickup the db config from /config/development/db.php(mysql) My understanding was if the environmental variable is development it will use /config/development/db.php and if the environmental variable is production it will use /config/production/db.php
  • As said, it will merge the generic one with the environment one. If you check both (as they are by default), the generic one contains all global definitions, including the driver to be used. The environment one only defines the database (the PDO dsn). If you want to switch to MySQL, use this layout for your development config:
    return array(
     'default' => array(
      'type'   => 'mysqli',
      'connection' => array(
       'hostname'   => 'localhost',
       'database'   => 'dbname_here',
       'username'   => 'user_here',
       'password'   => 'pass_here',
       'persistent' => FALSE,
      ),
      'table_prefix' => '',
      'charset'      => 'utf8',
      'caching'      => false,
      'profiling'    => true,
     ),
    );
    
  • Hello

    Does list_tables() supported or have any alternative functions now?
  • It does for MySQL via PDO, it doesn't for all other PDO drivers.

    If you use a different driver and need list_tables() support, create an issue at https://github.com/fuel/core/issues, stating the driver you use, and the SQL statement used to list the defined tables.

Howdy, Stranger!

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

In this Discussion