database config file - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: database config file (/showthread.php?tid=3640) |
database config file - El Forum - 10-15-2007 [eluser]cinewbie81[/eluser] Hi all, The following is my setup.php controller clas: Code: class Setup extends Controller { And the following is my database.php config: Code: $db['default']['hostname'] = "localhost"; When function index() loaded, the following error message prompted out: "Unable to select the specified database: payroll" This error is because I bind the value 'payroll' to $db['default']['database'] in my config file. It can be easily fixed if i manually query 'Create Database payroll' in prior, but i don't want it to be this way cause i don't want all my client have to manually create the database first before they can use the system. Any solution ?? database config file - El Forum - 10-15-2007 [eluser]sergitin[/eluser] hi I think first you most do Code: $db['default']['database'] = "mysql"; $db['default']['database'] to your database or you can have two DATABASE CONNECTIVITY SETTINGS in database.php the first is with Code: $active_group = "default"; Code: $active_group = "other"; at the other definition of connectivity database config file - El Forum - 10-15-2007 [eluser]Michael Wales[/eluser] Yeah - you're going to have to connect to some database to start off with (or modify the the database library to prevent it automatically selecting a database). database config file - El Forum - 10-15-2007 [eluser]cinewbie81[/eluser] [quote author="sergitin" date="1192477719"]hi I think first you most do Code: $db['default']['database'] = "mysql"; $db['default']['database'] to your database or you can have two DATABASE CONNECTIVITY SETTINGS in database.php the first is with Code: $active_group = "default"; Code: $active_group = "other"; at the other definition of connectivity[/quote] hi, thx, but how do u change the value $db['default']['database'] to my database from a function?? database config file - El Forum - 10-17-2007 [eluser]sergitin[/eluser] hi, sorry I'm late look at the user_guide folder on C.I. package /user_guide/database/connecting.html in that page, it's explained how to do two kind of connections with a very good examples I hope it works. database config file - El Forum - 10-17-2007 [eluser]cinewbie81[/eluser] Yeh the user_guide you mention show a good example how to sawitch between 2 "existing database" .. my problem now is "how to create a new database in my system then only connecting to it" .. sergitin and walesmd suggestion will work i suppose, but i don't actually know how to modify the value $db['default']['database'] from my other controller class .. do we have to open the config file then modify it manually which i think not user friendly enough for a system user database config file - El Forum - 10-17-2007 [eluser]sergitin[/eluser] I give you the option of to change the value of Code: $db['default']['database'] the other option is to begin with one connection setting and then you have created the other database then you can work with another connection variable and not to touch the original one... OK?? database config file - El Forum - 10-19-2007 [eluser]cinewbie81[/eluser] [quote author="sergitin" date="1192697313"]I give you the option of to change the value of Code: $db['default']['database'] the other option is to begin with one connection setting and then you have created the other database then you can work with another connection variable and not to touch the original one... OK??[/quote] Thanks. It's working now .. The code as following: Code: <?php Anyway, I've got another question.. I have Instead of have to load the database group everytime, how can I use this $DB1 and $DB2 value in other class of my project ?? Hope someone can help. Thanks ! |