CodeIgniter Forums
Database config file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Database config file (/showthread.php?tid=3656)



Database config file - El Forum - 10-15-2007

[eluser]cinewbie81[/eluser]
Hi all,

Sorry i post it on another forum previously, think that this is the right forum for me to post.. so here's it again ::


[quote author="cinewbie81" date="1192469868"]Hi all,

The following is my setup.php controller clas:

Code:
class Setup extends Controller {

function Setup()
{
  parent::Controller();
  $this->load->helper(array('url','form','setting'));
  $this->load->model('dbmodel', 'sql', TRUE);
  $this->load->database();

}
    
function index()
{
  $this->load->dbutil();
  if ($this->dbutil->create_database('payroll'))   {
      echo 'Database created!';
  }
}

}


And the following is my database.php config:

Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "password";
$db['default']['database'] = "payroll";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "";

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 ??[/quote]


Database config file - El Forum - 10-15-2007

[eluser]cinewbie81[/eluser]
Some forumites suggest me to set $db['default']['database'] to 'mysql' first, then only assign it to the databse i want after the database is created..

Now my problem is how am i going to change $db['default']['database'] value from other controller class ??