Home arrow PHP arrow Page 3 - Introduction to the CodeIgniter PHP Framework

Activating support for MySQL databases - PHP

In this group of articles, Iíll be taking a close look at the main features bundled with the CodeIgniter PHP framework. With it, you can quickly build small to moderate object-oriented applications. Now, itís time to begin harnessing the real power of CodeIgniter. Ignite yourself and start reading now!

TABLE OF CONTENTS:
  1. Introduction to the CodeIgniter PHP Framework
  2. Start using CodeIgniter
  3. Activating support for MySQL databases
  4. Developing the first application with Code Igniter
By: Alejandro Gervasio
Rating: starstarstarstarstar / 52
August 13, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As I said previously, the last file that youíll need to edit is the one located at /config/database.php. Open it and assign the correct values to the following settings:


$active_group = "default";

$active_record = TRUE;


$db['default']['hostname'] = "localhost";

$db['default']['username'] = "root";

$db['default']['password'] = "mypassword";

$db['default']['database'] = "mydatabase";

$db['default']['dbdriver'] = "mysql";

$db['default']['dbprefix'] = "";

$db['default']['pconnect'] = TRUE;

$db['default']['db_debug'] = TRUE;

$db['default']['cache_on'] = FALSE;

$db['default']['cachedir'] = "";

$db['default']['char_set'] = "utf8";

$db['default']['dbcollat'] = "utf8_general_ci";


As you can see, all of the above entries are self explanatory, since theyíre used by Code Igniter to connect to MySQL and select a particular database, which youíve probably done hundreds of times before.

However, in this case itís possible to work with several sets of connection values. Suppose for a moment that you need to use multiple development environments with a shared web server. In that case you might want to create a connection group for each of these environments in the following way:


$db['default']['hostname'] = "localhost";

$db['default']['username'] = "root";

$db['default']['password'] = "mypassword";

$db['default']['database'] = "mydatabase";

$db['default']['dbdriver'] = "mysql";

$db['default']['dbprefix'] = "";

$db['default']['pconnect'] = TRUE;

$db['default']['db_debug'] = FALSE;

$db['default']['cache_on'] = FALSE;

$db['default']['cachedir'] = "";

$db['default']['char_set'] = "utf8";

$db['default']['dbcollat'] = "utf8_general_ci";


$db['production']['hostname'] = "localhost";

$db[' production']['username'] = "root";

$db[' production']['password'] = "myotherpassword";

$db[' production']['database'] = "myotherdatabase";

$db[' production']['dbdriver'] = "mysql";

$db[' production']['dbprefix'] = "";

$db[' production']['pconnect'] = TRUE;

$db[' production']['db_debug'] = FALSE;

$db[' production']['cache_on'] = FALSE;

$db[' production']['cachedir'] = "";

$db[' production']['char_set'] = "utf8";

$db[' production']['dbcollat'] = "utf8_general_ci";


See how easy it is to set up two sets of MySQL connections for different development environments? I hope you do!

Finally, the ďactive_recordĒ entry should be activated when accessing MySQL database tables using the homonymous pattern. Actually, Code Igniter comes bundled with a bunch of methods that allow you to handle MySQL data via the active record approach. However, this topic will be covered in upcoming tutorials of this series, therefore, this option will be left enabled.

So far, these are all the array entries that youíll need to edit in the ďdatabase.phpĒ file in order to activate the support for MySQL databases. At this stage, everything has been properly setup to start developing object-oriented applications with Code Igniter!

In the section to come Iíll be showing you how to build a simple PHP program that uses the Model-View-Controller pattern in order to display a trivial message on the browser.

To learn how this initial sample application will be developed, click on the link below and keep reading.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: