<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CodeIgniter Tutorial</title>
	<atom:link href="http://www.gotphp.com/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gotphp.com</link>
	<description>Practical Coding Examples and Advice For PHP Developers</description>
	<lastBuildDate>Tue, 06 Sep 2011 01:01:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Storing Codeigniter Session Data to a Database</title>
		<link>http://www.gotphp.com/storing-codeigniter-session-data-to-a-database/54471/</link>
		<comments>http://www.gotphp.com/storing-codeigniter-session-data-to-a-database/54471/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 04:57:08 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[codeigniter database]]></category>
		<category><![CDATA[codeigniter form]]></category>
		<category><![CDATA[codeigniter sessions]]></category>
		<category><![CDATA[codeigniter tutorial]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sessions]]></category>

		<guid isPermaLink="false">http://www.gotphp.com/?p=471</guid>
		<description><![CDATA[One of the interesting things about CodeIgniter is how it creates and handles sessions. CodeIgniter doesn’t use native PHP sessions. Instead it uses a cookie to store the serialized data. This method, according to the guide, offers more flexibility for developers. In this example we’re going to try out the CI session class, and explore<a class="moretag" href="http://www.gotphp.com/storing-codeigniter-session-data-to-a-database/54471/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>One of the interesting things about CodeIgniter is how it creates and handles sessions. CodeIgniter doesn’t use native PHP sessions. Instead it uses a cookie to store the serialized data. This method, according to the guide, offers more flexibility for developers.</p>
<p>In this example we’re going to try out the CI session class, and explore storing session data in a database. We’ll use a simple ordering form to capture information, and play around the settings to get some pretty interesting results.</p>
<h2><strong>STEP 1: Configure CodeIgniter </strong></h2>
<p>Autoloading helpers and libraries is one of the ways CI helps simplify application development. So go ahead and load the&nbsp; database and session library on your config/autoload.php file . While we’re here, load the form and url helpers as well.</p>
<p>[sourcecode]<br />
$autoload['libraries'] = array(&#8216;database&#8217;, &#8216;session&#8217;);<br />
$autoload['helper'] = array(&#8216;form&#8217;, &#8216;url&#8217;);<br />
[/sourcecode]</p>
<p>On the same config folder, open up the config.php file and set up CI for saving session data to a database.</p>
<p>You want to look for:</p>
<p>[sourcecode]<br />
$config['sess_use_database']&nbsp;= TRUE;<br />
[/sourcecode]</p>
<p>Make sure to change that to TRUE. You can also specify the name of the database you want to use for your session data. Just look for:</p>
<p>[sourcecode]<br />
$config['sess_table_name']&nbsp;= &#8216;ci_sessions&#8217;;<br />
[/sourcecode]</p>
<p>By default the database is named <strong>ci_sessions</strong>, and that&#8217;s the name we&#8217;re going to use to create our database later on.</p>
<p>Now for this demonstration, we’re going to play around with the session expiration. So look for the line:</p>
<p>[sourcecode]<br />
$config['sess_expiration']&nbsp;= 7200;<br />
[/sourcecode]</p>
<p>Set the session expiration to 2 seconds. Normally, the session is set to expire in 2 days or 7200 seconds. But for this activity we want make multiple entries to our session database. So every two seconds the session expires and a new one can be created when the user submits new data from our ordering form.</p>
<h2><strong>STEP 2: Build the Database</strong></h2>
<p>Now that we have our config files set. Lets proceed to building our database. The CI user guide provides and excellent example of the basic prototype we can use for our database:</p>
<p>[sourcecode]<br />
CREATE TABLE IF NOT EXISTS&nbsp; `ci_sessions` (<br />
session_id varchar(40) DEFAULT &#8217;0&#8242; NOT NULL,<br />
ip_address varchar(16) DEFAULT &#8217;0&#8242; NOT NULL,<br />
user_agent varchar(50) NOT NULL,<br />
last_activity int(10) unsigned DEFAULT 0 NOT NULL,<br />
user_data text NOT NULL,<br />
PRIMARY KEY (session_id)<br />
);<br />
[/sourcecode]</p>
<p>Go ahead and take a look at the database table that was created. Inside the ci_sessions table you&#8217;ll see five fields:</p>
<ol>
<li>session_id</li>
<li>ip_address</li>
<li>user_agent</li>
<li>last_activity</li>
<li>user_data</li>
</ol>
<p>The user_data field is where our custom data will be stored later on.</p>
<h2><strong>STEP 3: Create the Form</strong></h2>
<p>Ok, we’ve got our database ready. Lets take it for a spin by building a simple ordering form. In our views folder, you want to create sessionexample.php file with the following code:</p>
<p>[sourcecode]<br />
&lt;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;<br />
&lt;head&gt;<br />
&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text/html; charset=utf-8&#8243; /&gt;<br />
&lt;title&gt;Order Form&lt;/title&gt;<br />
&lt;link type=&#8221;text/css&#8221; rel=&#8221;stylesheet&#8221; href=&#8221;&lt;?php echo base_url();?&gt;css/style.css&#8221; &gt;<br />
&lt;/head&gt;</p>
<p>&lt;body&gt;<br />
&lt;h5&gt;Fruity Orders&lt;/h5&gt;<br />
&lt;?php<br />
$attributes = array(<br />
&#8216;name&#8217; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;=&gt; &#8216;orderform&#8217;<br />
, &#8216;id&#8217; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;=&gt; &#8216;orderform&#8217;<br />
);<br />
echo form_open(&#8216;sessionexample/process&#8217;, $attributes);</p>
<p>echo form_label(&#8216;Order for: &#8216;, &#8216;ordername&#8217;);<br />
echo form_input(&#8216;ordername&#8217;).&#8217;&lt;br /&gt;&#8217;;</p>
<p>echo form_label(&#8216;How Many: &#8216;, &#8216;quantity&#8217;);<br />
$data = array(<br />
&#8216;name&#8217; =&gt; &#8216;quantity&#8217;<br />
, &#8216;id&#8217; =&gt; &#8216;quantity&#8217;<br />
, &#8216;maxlength&#8217; =&gt; &#8217;2&#8242;<br />
, &#8216;size&#8217; =&gt; &#8217;1&#8242;<br />
);<br />
echo form_input($data).&#8217; &#8216;;</p>
<p>echo form_label(&#8216;Choose Item &#8216;, &#8216;choice&#8217;);<br />
$options = array(<br />
&#8216;apples&#8217; =&gt; &#8216;Apples&#8217;<br />
, &#8216;oranges&#8217; =&gt; &#8216;Oranges&#8217;<br />
, &#8216;pears&#8217; =&gt; &#8216;Pears&#8217;<br />
);<br />
echo form_dropdown(&#8216;choice&#8217;, $options, &#8216;apples&#8217;).&#8217;&lt;br /&gt;&#8217;;</p>
<p>echo form_submit(&#8216;submit&#8217;, &#8216;Send My Order&#8217;);<br />
echo form_close();</p>
<p>echo (isset($message) ? &#8220;&lt;div class=&#8217;message&#8217;&gt;&#8221;.$message.&#8221;&lt;/div&gt;&#8221; : NULL);<br />
?&gt;</p>
<p>&lt;/body&gt;<br />
&lt;/html&gt;<br />
[/sourcecode]</p>
<h2><strong>STEP 4: Create the Controller</strong></h2>
<p>Now for the fun part. Create a file called sessionexample.php in the controllers folder. Inside it, we’re going to catch the data as the user submits his order, then store the data into our session using flashdata.</p>
<p>[sourcecode]<br />
class Sessionexample extends MY_Controller {<br />
function __construct(){<br />
parent::__construct();<br />
}</p>
<p>function index(){<br />
$this-&gt;load-&gt;view(&#8216;sessionexample&#8217;);<br />
}</p>
<p>function process(){<br />
$values = array(<br />
&#8216;ordername&#8217; &nbsp;&nbsp; &nbsp;=&gt; $this-&gt;input-&gt;post(&#8216;ordername&#8217;)<br />
, &#8216;quantity&#8217; &nbsp;&nbsp; &nbsp;=&gt; $this-&gt;input-&gt;post(&#8216;quantity&#8217;)<br />
, &#8216;choice&#8217; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;=&gt; $this-&gt;input-&gt;post(&#8216;choice&#8217;)<br />
);<br />
$this-&gt;session-&gt;set_flashdata($values);</p>
<p>$data['message'] &nbsp;&nbsp; &nbsp;= &#8220;You ordered &#8220;.$values['quantity'];<br />
$data['message'] &nbsp;&nbsp; &nbsp;.= &#8221; &#8220;.$values['choice'].&#8221; for &#8220;.$values['ordername'].&#8221;.&#8221;;</p>
<p>$this-&gt;load-&gt;view(&#8216;sessionexample&#8217;, $data);<br />
}<br />
}<br />
[/sourcecode]</p>
<p>Notice that after storing the user data, we retrieve it from the session object and send it back to our view as feedback for the user. You can take the application for a spin now or finish off with some styles.&nbsp; After as the session is created, CI automatically stores the information to our database. Since we tweaked the session expiration to 2 seconds, you can make multiple database entries to observe how CI stores the information.</p>
<h2><strong>STEP 5 (Optional): Finish with style </strong></h2>
<p>Let’s polish off our web application with styling. We’re also going to link a style sheet to our order form:</p>
<p>[sourcecode]<br />
&lt;link type=&#8221;text/css&#8221; rel=&#8221;stylesheet&#8221; href=&#8221;&lt;?php echo base_url();?&gt;css/style.css&#8221; &gt;<br />
[/sourcecode]</p>
<p>Go ahead and create style.css where we’re going to place the following styles:</p>
<p>[sourcecode]<br />
body {<br />
background: #EFB4B3;<br />
margin: 0; padding: 0;<br />
font-family: arial;<br />
}</p>
<p>#orderform {<br />
border: 1px solid black;<br />
margin: 15px auto 0; padding: 1em;<br />
width: 350px;<br />
-moz-border-radius: 5px;<br />
-webkit-border-radius: 5px;<br />
}</p>
<p>.message {<br />
background: #FFFFCC;<br />
margin: 15px auto 0; padding: 1em;<br />
width: 350px;<br />
-moz-border-radius: 5px;<br />
-webkit-border-radius: 5px;<br />
}</p>
<p>h5 {<br />
color: #336699;<br />
font-size:24px; font-weight:bold;<br />
margin-bottom: 2px;<br />
text-align: center;<br />
}</p>
<p>input[type=text], select {<br />
margin: 0 0 1em 0; padding: 2px;<br />
width: auto;<br />
border: 5px;<br />
font-size:14px;<br />
-moz-border-radius: 1px;<br />
-webkit-border-radius: 1px;<br />
}</p>
<p>input[type=submit]{<br />
background: #3399FF;<br />
border: none;<br />
padding: 6px;<br />
text-decoration: none;<br />
color: white; font-size: 12px;<br />
-moz-border-radius: 4px;<br />
-webkit-border-radius: 4px;<br />
}</p>
<p>input[type=submit]:hover{<br />
background: #0099CC;<br />
cursor: pointer;<br />
}<br />
[/sourcecode]</p>
<p>There you have it, a quick and simple demo on how to store CodeIgniter Session Data on a database.</p>
<div style="width: 1px;height: 1px;overflow: hidden">sessionexample</div>
<p><script type="text/javascript" src="http://forms.aweber.com/form/32/159230832.js"></script></p>
<p><strong>If you found this article useful, please share your comments below.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotphp.com/storing-codeigniter-session-data-to-a-database/54471/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Tip &#8211; How To Switch Between Two Databases</title>
		<link>http://www.gotphp.com/codeigniter-tip-how-to-switch-between-two-databases/54442/</link>
		<comments>http://www.gotphp.com/codeigniter-tip-how-to-switch-between-two-databases/54442/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 18:05:15 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[codeigniter multiple databases]]></category>
		<category><![CDATA[database]]></category>

		<guid isPermaLink="false">http://www.gotphp.com/?p=442</guid>
		<description><![CDATA[Most development starts locally (meaning local to the developer). This &#8220;usually&#8221; means that your database is local as well. However once your application is online and live, you now have two databases to keep up with for future development and most importantly ongoing testing. Here&#8217;s a little tip on how to manage both database settings<a class="moretag" href="http://www.gotphp.com/codeigniter-tip-how-to-switch-between-two-databases/54442/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>Most development starts locally (meaning local to the developer). This &#8220;usually&#8221; means that your database is local as well. However once your application is online and live, you now have two databases to keep up with for future development and most importantly ongoing testing.</p>
<p>Here&#8217;s a little tip on how to manage both database settings from your local sandbox and easily switch between the two databases.</p>
<p><strong>Simply add two database config blocks in your database.php config file and use the $active_group variable to switch between the two databases.</strong></p>
<pre class="brush:php">$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "pm5_client";
$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";

$db['coaching']['hostname'] = "db.domain.com";
$db['coaching']['username'] = "xxx";
$db['coaching']['password'] = "xxx";
$db['coaching']['database'] = "xxx";
$db['coaching']['dbdriver'] = "mysql";
$db['coaching']['dbprefix'] = "";
$db['coaching']['pconnect'] = TRUE;
$db['coaching']['db_debug'] = TRUE;
$db['coaching']['cache_on'] = FALSE;
$db['coaching']['cachedir'] = "";
$db['coaching']['char_set'] = "utf8";
$db['coaching']['dbcollat'] = "utf8_general_ci";</pre>
<p><strong>In the example above, if I want to <span style="text-decoration: underline;">connect to my local database</span> I use:</strong></p>
<pre class="brush:php">$active_group = "default";</pre>
<p><strong>And if I want to <span style="text-decoration: underline;">connect to my remote (production) database</span>, I use:</strong></p>
<pre class="brush:php">$active_group = "coaching";</pre>
<p><strong>That&#8217;s it. Enjoy!</strong></p>
<p><script type="text/javascript" src="http://forms.aweber.com/form/32/159230832.js"></script></p>
<p><strong>If you found this article useful, please share your comments below.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotphp.com/codeigniter-tip-how-to-switch-between-two-databases/54442/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter with Multiple Database Support</title>
		<link>http://www.gotphp.com/codeigniter-multiple-database-support/5468/</link>
		<comments>http://www.gotphp.com/codeigniter-multiple-database-support/5468/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 14:24:57 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[codeigniter multiple databases]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[profiler]]></category>

		<guid isPermaLink="false">http://www.gotphp.com/?p=68</guid>
		<description><![CDATA[** UPDATED on 2010-09-06 ** Over the last few months I have been using the CodeIgniter framework for several projects. So far, I have been very pleased with its flexibility and even more so with its extensibility. On one my projects, I needed to connect to multiple databases at the same time. CI easily supports<a class="moretag" href="http://www.gotphp.com/codeigniter-multiple-database-support/5468/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p><strong>** UPDATED on 2010-09-06 **</strong></p>
<p>Over the last few months I have been using the <a href="http://codeigniter.com/" target="_blank">CodeIgniter</a> framework for several projects. So far, I have been very pleased with its flexibility and even more so with its extensibility.</p>
<p>On one my projects, I needed to connect to multiple databases at the same time. CI easily supports this via configuration settings, however the built in profiler only supports the default database. No problem, let&#8217;s extend it!</p>
<h2 id="section-1">Step 1: Edit database.php and use descriptive group names.</h2>
<p>In this tutorial, I am connecting to 2 separate databases. So far, this is nothing new, however your settings need to be correct.</p>
<p><strong>Example:</strong></p>
<pre class="brush:php">
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "";
$db['default']['username'] = "";
$db['default']['password'] = "";
$db['default']['database'] = "";
$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";

// add alternate database settings by gotphp.com

$db['alternate']['hostname'] = "";
$db['alternate']['username'] = "";
$db['alternate']['password'] = "";
$db['alternate']['database'] = "";
$db['alternate']['dbdriver'] = "mysql";
$db['alternate']['dbprefix'] = "";
$db['alternate']['pconnect'] = TRUE;
$db['alternate']['db_debug'] = TRUE;
$db['alternate']['cache_on'] = FALSE;
$db['alternate']['cachedir'] = "";
$db['alternate']['char_set'] = "utf8";
$db['alternate']['dbcollat'] = "utf8_general_ci";
</pre>
<h2 id="section-2">Step 2: Edit autoload.php and autoload ALL models.</h2>
<p>This is needed so the profiler is aware of the other databases and can iterate accordingly. </p>
<p><strong>IMPORTANT:</strong> If you ONLY load your models on demand, that&#8217;s OK too. You still want to follow this step, but simply comment out the <code>$autoload</code> variable when you are NOT in debug mode. <img src='http://www.gotphp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Example:</strong></p>
<pre class="brush:php">
$autoload['model'] = array(
	'alternate_model', 	// loaded by gotphp.com
	'default_model', 	// loaded by gotphp.com
);
</pre>
<h2 id="section-3">Step 3: In your models, use the actual database group names for your db connection by defining $db_group_name.</h2>
<p>In other words, stop using <code>$this->db</code> and start using <code>$this->[group]</code>, etc. </p>
<p><strong>IMPORTANT:</strong> Be sure to establish a connection to the database group in the model&#8217;s constructor AND add a new method to get the database group for this mode. <strong>THIS IS REQUIRED.</strong></p>
<p><strong>Example:</strong></p>
<pre class="brush:php">
class Default_model extends Model {

	/**
	 */
	var $db_group_name = "default";

	// --------------------------------------------------------------------

	/**
	 * 	Constructor -- Loads parent class
	 */
	function __construct()
	{
		parent::__construct();

		$this->{$this->db_group_name} = $this->load->database($this->db_group_name, TRUE);

	}

	// --------------------------------------------------------------------

	/**
	 * 	Required method to get the database group for THIS model
	 */
	function get_database_group() {
		return $this->db_group_name;
	}

	// --------------------------------------------------------------------

}
</pre>
<p><strong>Now in EACH method in THIS model, use <code>$this->{$this->db_group_name}</code>.</strong></p>
<p><strong>Example:</strong></p>
<pre class="brush:php">
class Default_model extends Model {

	// --------------------------------------------------------------------

	function get_example_data()
	{
		$query = $this->{$this->db_group_name}->get('default_example');
		return $query->result_array();
	}

	// --------------------------------------------------------------------

}
</pre>
<h2 id="section-4">Step 4: Extend CI&#8217;s profiler class to include all databases in the debug output</h2>
<p>In your <code>config.php</code> file, take note of your <code>subclass_prefix</code> setting. You will need to use this in order to extend CI&#8217;s core classes automatically.</p>
<p><strong>Example:</strong></p>
<pre class="brush:php">
$config['subclass_prefix'] = 'MY_';
</pre>
<p>Now, create a new file in your application&#8217;s libraries directory called <code>MY_Profiler.php</code>. </p>
<p><strong>IMPORTANT:</strong> If you changed your <code>subclass_prefix</code>, replace &#8220;<code>MY_</code>&#8221; in the rest of this tutorial with your custom setting.</p>
<p>In this new file, you will be extending the <code>CI_Profiler</code>, defining your own run method to account for multiple database groups, and adding a new display method that shows the database group AND model for each query!</p>
<p><strong>Example:</strong></p>
<pre class="brush:php">
class MY_Profiler extends CI_Profiler {

	/**
	 * Compile Multiple Database Queries
	 * @return	string
	 */
	function _compile_multi_db_queries($database, $model)
	{
		... too much to copy here ... download file to review ...
	}

	// --------------------------------------------------------------------

	/**
	 * Run the Profiler
	 *
	 * @access	private
	 * @return	string
	 */
	function run()
	{
		$output = "
<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>";

		if ($this->CI->config->item('show_uri_string')) { 		$output .= $this->_compile_uri_string(); }
		if ($this->CI->config->item('show_controller_info')) { 	$output .= $this->_compile_controller_info(); }
		if ($this->CI->config->item('show_memory_usage')) { 	$output .= $this->_compile_memory_usage(); }
		if ($this->CI->config->item('show_benchmarks')) { 		$output .= $this->_compile_benchmarks(); }
		if ($this->CI->config->item('show_cookies')) { 			$output .= $this->_compile_variables('cookie_vars'); }
		if ($this->CI->config->item('show_get_vars')) { 		$output .= $this->_compile_variables('get_vars'); }
		if ($this->CI->config->item('show_post_vars')) { 		$output .= $this->_compile_variables('post_vars'); }
		if ($this->CI->config->item('show_uri_vars')) { 		$output .= $this->_compile_variables('uri_vars'); }
		if ($this->CI->config->item('show_tpl_vars')) { 		$output .= $this->_compile_variables('tpl_vars'); }
		if ($this->CI->config->item('show_session_userdata')) { $output .= $this->_compile_variables('session_userdata'); }

		if ($this->CI->config->item('show_db_multi_queries')) {

			// Include the autoload config to access the array of models in this app.
			include(APPPATH.'config/autoload'.EXT);

			// Loop through each model to set the database object
			foreach($autoload['model'] as $model) {

				// Define the database object name
				$database = $this->CI->$model->get_database_group();

				// Compile the output
				$output .= $this->_compile_multi_db_queries($database, $model);

			}

		} else {

			$output .= $this->_compile_queries();		

		}

		$output .= '</div>

';

		return $output;
	}

	// --------------------------------------------------------------------

}
</pre>
<h2>Step 5: You will need to enable the built in profiler in one of your controllers and set the new configuration paramaters in a <code>profile.php</code> config file.</h2>
<p><strong>Example (enable profiler):</strong></p>
<pre class="brush:php">
// Load the profile.php config file if it exists
$this->config->load('profiler', false, true);
if ($this->config->config['enable_profiler']) {
	$this->output->enable_profiler(TRUE);
}
</pre>
<p><strong>Example (profiler.php file):</strong></p>
<pre class="brush:php">
$config['enable_profiler'] 			= 1;
$config['show_uri_string'] 			= 1;
$config['show_controller_info']		= 1;
$config['show_memory_usage'] 		= 1;
$config['show_benchmarks'] 			= 1;
$config['show_cookies'] 			= 1;
$config['show_get_vars'] 			= 1;
$config['show_post_vars'] 			= 1;
$config['show_uri_vars'] 			= 1;
$config['show_tpl_vars'] 			= 1;
$config['show_session_userdata']	= 1;
$config['show_db_multi_queries'] 	= 1; // Only enable if you need to show more than one database in the profiler
</pre>
<p>If you have followed the steps above in order, your CodeIgniter application can now connect to multiple databases at the same time and each connections&#8217; queries will display in the profiler like this:</p>
<p><a href="http://www.gotphp.com/wp-content/gotphp-uploads/profiler-example-multi-db.png"><img src="http://www.gotphp.com/wp-content/gotphp-uploads/profiler-example-multi-db.png" alt="Profiler Example Multi DB" title="Profiler Example Multi DB" width="386" height="162" class="alignnone size-full wp-image-394" /></a></p>
<p><script type="text/javascript" src="http://forms.aweber.com/form/32/159230832.js"></script></p>
<p><strong>If you found this article useful, please share your comments below.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gotphp.com/codeigniter-multiple-database-support/5468/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

