PHP
  Home arrow PHP arrow Page 3 - Introduction to the CodeIgniter PHP Fr...
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Introduction to the CodeIgniter PHP Framework
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 11
    2008-08-13

    Table of Contents:
  • Introduction to the CodeIgniter PHP Framework
  • Start using CodeIgniter
  • Activating support for MySQL databases
  • Developing the first application with Code Igniter

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to the CodeIgniter PHP Framework - Activating support for MySQL databases


    (Page 3 of 4 )

    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


       · Code Igniter is a powerful, easy-to-setup PHP framework that lets developers build...
       · CodeIgniter is a very easy framework to get into and it's great to see this...
       · Thank you for the suggestions about Kohana framework. I think they’ll be useful for...
       · I have been coding PHP and just learn CI Framework, i think it's useful especially...
       · Thanks for commenting on my CI article. If you’re learning how to implement the MVC...
       · Zend is not a framework...'ZEND Framework', however, is a framework. 'ZEND' can be...
       · Thanks for commenting on my CI article. Actually, Zend is a framework and not ZEND....
       · thank you for the tutorial system. I am shocked at how ungrateful some people are....
       · Thanks for the words on my CI article. I really appreciate your recognition on my...
       · Am simply reiterating the message extended by Zend Technologies and those developing...
       · Helpful contribution, indeed. While being appreciated, it's rather irrelevant with...
       · I've been 'playing around' with PHP fopr a while now, and CI is my first dip in the...
       · Thanks Martin for the words on my series on using CI's main features. Glad to know...
     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT