HOW TO CONFIGURE CODEIGNITER WITH POSTGRESQL

 


At present, I’m doing a project for one of my subjects. Students must use a Database Management System or DBMS. We only have two options. One of this is to use Postgres. For the project, it was decided to use Postgres together with PHP, with the help of framework called CodeIgniter.
Before proceeding with the steps, it would be better if you already know how to make Entity Relationship Diagram (ERD) based from specifications and assumptions, tables, normalized tables and SQL for creating tables with constraint. You have to use your SQL file for creating tables which suits your needs. But if you want to have access on a dummy table which you can use for this tutorial, please feel free to contact me.
Anyway, let’s now start by setting up your environment or preparing all the things that you need.
1. Download BITNAMI WAPP STACK from: http://bitnami.com/stack/wapp
Install it. When asked, set the required fields according to your preferences. Please remember this important details.

Username: myusername
Password: mypassword
Database name : mydatabasename
2. Download CodeIgniter Framework from: http://ellislab.com/codeigniter/user-guide/installation/downloads.html
Choose CodeIgniter V 2.1.4 (Current version)
3. Extract the files and move the folder to: C://BITNAMI/Wappstack-5.4.17.0/apache2/htdocs/yourfoldername.
4. Open WAPP Stack . Choose “MANAGE SERVERS” tab. Make sure that Apache Webserver and Postgres status is running.
If not running, click the start buttons.
5. Open a browser (chrome). Go to http://127.0.0.1/phppgadmin/. Login using the details we entered. If there is no database, create a database with “mydatabasename” as its name.
6. Create tables by clicking schema, then SQL button. Click choose file and select sql file where you saved your DDL. This should contain SQL for creating tables. Click execute.
Make sure that there were no error messages. If it’s successful you will see only CREATE TABLE messages.
7. Populate other tables using SQL again. Start by clicking schema, then SQL button. Click choose files. Select the files which contains insert statement. Prioritize inserting the tables without foreign keys to avoid errors. Click execute. Do this for each file. Make sure that there are no error messages.
8. Configure CodeIgniter with Postgres. Go to the following folder “C://BITNAMI/Wappstack-5.4.17.0/apache2/htdocs/yourfoldername/application. Open database.php.
Make changes and follow this information which we set earlier:
$db[‘default’][‘hostname’] = ‘localhost’;
$db[‘default’][‘username’] = ‘myusername’;
$db[‘default’][‘password’] = ‘mypassword’;
$db[‘default’][‘database’] = ‘mydatabasename’;
$db[‘default’][‘dbdriver’] = ‘postgre’;
9. Open route.php from the same folder. Make the following changes:

$route[‘default_controller’] = “mycontroller”;
That’s it for part 1. On the next tutorial, I will show you how to test if your database is already connected.
References: CodeIgniter User Guide

To know more about CodeIgniter, you may check this book:
CodeIgniter 

Post a Comment

0 Comments