<?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/profiler/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>CodeIgniter Profiler Extended</title>
		<link>http://www.gotphp.com/codeigniter-profiler-extended/54358/</link>
		<comments>http://www.gotphp.com/codeigniter-profiler-extended/54358/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 05:07:27 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[CodeIgniter Profiler]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[profiler]]></category>

		<guid isPermaLink="false">http://www.gotphp.com/?p=358</guid>
		<description><![CDATA[CodeIgniter includes a built in Profiler class that really helps debugging your php applications in real-time. I highly recommend using it if you aren&#8217;t already. It&#8217;s really simple to enable, just add this one line to your php code and refresh your application. $this-&#62;output-&#62;enable_profiler(TRUE); The profiler data will be displayed in the footer of your<a class="moretag" href="http://www.gotphp.com/codeigniter-profiler-extended/54358/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>CodeIgniter includes a built in Profiler class that really helps debugging your php applications in real-time. I highly recommend using it if you aren&#8217;t already. It&#8217;s really simple to enable, just add this one line to your php code and refresh your application. </p>
<pre class="brush:php">
$this-&gt;output-&gt;enable_profiler(TRUE);
</pre>
<p><em>The profiler data will be displayed in the footer of your php application.</em></p>
<p>While the default CodeIgniter Profiler class is good, I&#8217;ve been using an extended version that displays a lot more debugging information and uses a profiler.php config file for easy of use.</p>
<p>Here&#8217;s how to use it in your php application.</p>
<h2 id="section-1">Step 1: Create a profiler.php config file and include the following config options.</h2>
<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'] 	= 0; // Only enable if you need to show more than one database in the profiler
</pre>
<h2 id="section-2">Step 2. Add the following lines to the constructor of your current controller or in the constructor of a parent controller.</h2>
<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>
<h2 id="section-3">Step 3. Upload the custom My_Profiler.php file to your libraries directory.</h2>
<p><em>And here&#8217;s what you new profiler will look like:</em></p>
<p><a href="http://www.gotphp.com/wp-content/gotphp-uploads/profiler-example-full.png"><img src="http://www.gotphp.com/wp-content/gotphp-uploads/profiler-example-full-204x300.png" alt="CodeIgniter Profiler Extended" title="CodeIgniter Profiler Extended" width="204" height="300" class="alignnone size-medium wp-image-408" /></a></p>
<p><em>Be sure to change the &#8220;subclass_prefix&#8221; to match what you have in your config.php file.</em></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-profiler-extended/54358/feed/</wfw:commentRss>
		<slash:comments>5</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>

