Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Create database connection in runtime
boniface
November 2016
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!
Harro
November 2016
You can set config values in your code:
http://fuelphp.com/docs/classes/config.html#/method_set
and when done, save it:
http://fuelphp.com/docs/classes/config.html#/method_save
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".
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
November 2016