Step 3: Set up the database that will be used by CodeIgniter

(created at: November 7, 2014; last update: January 23, 2015)

I won’t teach you how to create a database. You can use phpMyAdmin (or any other MySQL client for that matter) to do what you need. Also, you may have different connection parameters depending on your environment. One set of connection parameters for your development environment and another set for your live (production) server.

Once you’ve created the database(s), you must configure the CodeIgniter to allow the app to connect when needed.

For this we will use the database.php file that we moved in the previous step inside application/config/development/ folder. Also, if you’ve already set up databases for testing and production environments, you can copy database.php inside the coresponding directories.

Inside database.php we only have to make a few changes. You will find a $db array with a ‘default’ key. In it we will have to change the values corresponding to the keys: hostname, username, password, database.

Once we’ve done the changes, we should verify if all went well. To do that, we open the autoload.php file inside application/config, and we change the line:

to:

…and save the file. If something went wrong, when we visit our site we should see an error. If that happens, make sure you’ve set up correctly the database configuration.

Instead, if everything went well and you are greeted with the “Welcome to CodeIgniter!” message, you should – for the moment at least – stop “autoloading” the database library. For now we don’t need to connect to the database for any single request coming from the browser. So go back to your autoload.php and return to:

 

0 thoughts on “Step 3: Set up the database that will be used by CodeIgniter

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

No spam? * Time limit is exhausted. Please reload CAPTCHA.