Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Create database connection in runtime
  • I'm planning to build a application, that can be installed on a server using fuel.
    I need to create a UI where the user will enter their database details, just like how wordpress displays its database setup page.

    Is there a way to write database details on fuel config at run-time ?
    Can i test connection to a database using Fuel's functionality ?

    Thanks for the amazing framework!
  • You can set config values in your code:

    and when done, save it:

    so something like:

    \Config::load('db', true);

    $db = array(
        'default' => array(
            'type'        => 'pdo',
            'connection'  => array(
                'dsn'        => 'mysql:host=localhost;dbname=TestDB,
                'username'   => 'username',
                'password'   => 'password',
            'profiling'    => true,

    \Config::set('db.default', $db);
    \Config::save('db', 'db');

    disclaimer: from the top of my head, so try it first!. It will write the config file to the APPPATH/config directory, if you want to write the config to a specific environment, you need to prefix the file, like "staging/db".

Howdy, Stranger!

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

In this Discussion