<?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>dijexi.com &#187; PHP</title>
	<atom:link href="http://www.dijexi.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dijexi.com</link>
	<description>free programming tutorial, tips and tricks on php, codeigniter, delphi, dotnet, ajax and more..</description>
	<lastBuildDate>Fri, 13 Jan 2012 23:21:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Introduction to PHP AGI (Asterisk Gateway Interface)</title>
		<link>http://www.dijexi.com/2010/08/introduction-to-php-agi-asterisk-gateway-interface/</link>
		<comments>http://www.dijexi.com/2010/08/introduction-to-php-agi-asterisk-gateway-interface/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 07:48:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[VOIP]]></category>
		<category><![CDATA[php agi]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2010/08/introduction-to-php-agi-asterisk-gateway-interface/</guid>
		<description><![CDATA[The (AGI) Asterisk Gateway Interface is an interface for adding functionality to Asterisk with many different programming languages. Perl, PHP, C, Pascal, Bourne Shell, or any other programming language that you like. To use AGI, create an extension on extension.conf, with this format (example extension number 5151): exten =&#62; 5151,1,AGI(test.php) &#160; Then place the script [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>The (AGI) Asterisk Gateway Interface is an interface for adding functionality to Asterisk with many different programming languages. Perl, PHP, C, Pascal, Bourne Shell, or any other programming language that you like.</p>
<p>To use AGI, create an extension on extension.conf, with this format (example extension number 5151):</p>
<blockquote><p>exten =&gt; 5151,1,AGI(test.php)     </p>
</blockquote>
<p>&#160;</p>
<p>Then place the script (for example in PHP, test.php) on the specified AGI folder in asterisk.conf, for example in /var/lib/asterisk/agi-bin.</p>
<p>The script should be executable, so you must first chmod +x to the script. </p>
<p>As an example, let create simple AGI application that fetch the web for a currency data and speak it to the caller. To simplify our self, we are going to use PHP and PHPAGI library. </p>
<p> <span id="more-1333"></span>
<p>The web service URL that we are going to fetch is located at <a title="http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&amp;ToCurrency=IDR" href="http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&amp;ToCurrency=IDR">http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=USD&amp;ToCurrency=IDR</a></p>
<p>This will return the conversion rate in XML format of the FromCurrency to the ToCurrency. For simplicity we make it hard coded now. You can change the values for the both parameters.</p>
<p>Before we begin, first download latest version of PHP AGI library from <a title="http://sourceforge.net/projects/phpagi/" href="http://sourceforge.net/projects/phpagi/">http://sourceforge.net/projects/phpagi/</a>, extract, and put phpagi.php, phpagi-asmanager.php, and phpagi-fastagi.php files on /var/lib/asterisk/agi-bin.</p>
<p>Also, you need to install Fextival text to speech so that Asterisk can answer the caller using the text that we supply.</p>
<p>Let’s create a new PHP script and save it on /var/lib/asterisk/agi-bin as curr.php. Here is the source code:</p>
<blockquote><p>#!/usr/bin/php -q     <br />&lt;? </p>
<p>set_time_limit(30);     <br />//load PHP AGI      <br />require(&#8216;phpagi.php&#8217;);      <br />$agi = new AGI(); </p>
<p>//answer the call     <br />$agi-&gt;answer(); </p>
<p>//fetch the web service and store the result into $curr     <br />$fromCurrency=&quot;USD&quot;;      <br />$toCurrency=&quot;IDR&quot;;      <br />$res=file_get_contents(&quot;<a href="http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=">http://www.webservicex.com/CurrencyConvertor.asmx/ConversionRate?FromCurrency=</a>$fromCurrency&amp;ToCurrency=$toCurrency&quot;);      <br />$xml = new SimpleXMLElement($res);      <br />$curr=$xml[0]; </p>
<p>$agi-&gt;text2wav(&quot;Currency rate from $fromCurrency to $toCurrency is&quot;);     <br />$agi-&gt;say_number($curr);      <br />$agi-&gt;text2wav(&quot;Thank you&quot;);      <br />$agi-&gt;hangup(); </p>
<p>?&gt;</p>
</blockquote>
<p>&#160;</p>
<p>A few thing to consider on the above code:</p>
<p>First we set the allowable processing time limit to 30 seconds, and load the PHP AGI library, then we instantiate the <em>$agi</em> variable. Then we answer the call using <em>$agi-&gt;answer().</em></p>
<p>Then we fetch the currency data from the web service URL, and store the data into <em>$res</em> variable which is an XML string. We convert it into XML object by using <em>SimpleXMLElement</em>, and get the conversion value which is stored on <em>$xml[0]</em> and store it into <em>$curr </em>variable. You may inspect the XML structure by calling print_r($xml).</p>
<p>Next we call <em>$agi-&gt;text2wav()</em> that will say anything supplied into it’s parameter. And we call <em>$agi-&gt;say_number($curr)</em>. At the end, we say thank you and hang up the phone by <em>$agi-&gt;hangup()</em>.</p>
<p>Now edit /etc/asterisk/extension.conf and add the following lines under the context that your phone can access, for example Internal context.</p>
<blockquote><p>[Internal]     <br />exten =&gt; 5151,1,AGI(curr.php)</p>
</blockquote>
<p>&#160;</p>
<p>Call the extension number 5151 from your phone, and you will get replied by the system telling you the currency rate between USD and IDR.. But don’t get surprised with the big value, this is Indonesia :( </p>
<p>Further PHP AGI functions that might interest you are:</p>
<ol>
<li><a href="http://phpagi.sourceforge.net/phpagi2/docs/phpAGI/AGI.html#get_data">get_data</a> to get DTMF data for you application to process, like the IVR menu</li>
<li><a href="http://phpagi.sourceforge.net/phpagi2/docs/phpAGI/AGI.html#parse_callerid">parse_callerid</a> to parse and get the caller ID information&#160; </li>
<li><a href="http://phpagi.sourceforge.net/phpagi2/docs/phpAGI/AGI.html#record_file">record_file</a> to record caller’s voice</li>
</ol>
<p>For further information and consultation, you may contact me directly:</p>
<p>Akhmad Daniel Sembiring   <br />akhmad.daniel[at]gmail.com    <br />vitraining.com – CEO</p>
<p>&#160;</p>
<p>Further reading:</p>
<ol>
<li><a title="http://www.voip-info.org/wiki/view/Asterisk+AGI" href="http://www.voip-info.org/wiki/view/Asterisk+AGI">http://www.voip-info.org/wiki/view/Asterisk+AGI</a></li>
<li><a title="http://sourceforge.net/projects/phpagi/" href="http://sourceforge.net/projects/phpagi/">http://sourceforge.net/projects/phpagi/</a></li>
<li><a href="http://www.asterisk.org">http://www.asterisk.org</a> </li>
</ol>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2010/08/how-to-install-asterisk-1-6-on-ubuntu/" rel="bookmark">How to install Asterisk 1.6 on Ubuntu</a></li><li><a href="http://www.dijexi.com/2010/05/setup-kannel-sms-gateway-on-ubuntu/" rel="bookmark">Setup Kannel SMS Gateway on Ubuntu</a></li><li><a href="http://www.dijexi.com/2009/07/best-free-development-tools-and-editors-software/" rel="bookmark">Best Free Development Tools and Editors Software</a></li><li><a href="http://www.dijexi.com/2009/06/tutorial-membuat-aplikasi-point-of-sales/" rel="bookmark">15. Aplikasi Point of Sales</a></li><li><a href="http://www.dijexi.com/2009/07/best-free-browsers-instant-messengers-remote-file-management-shell-and-linux-emulation-software/" rel="bookmark">Best Free Browsers, Instant Messengers, Remote File Management, Shell and Linux Emulation Software</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2010%2F08%2Fintroduction-to-php-agi-asterisk-gateway-interface%2F&amp;linkname=Introduction%20to%20PHP%20AGI%20%28Asterisk%20Gateway%20Interface%29"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2010/08/introduction-to-php-agi-asterisk-gateway-interface/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Use Tor Project Anonymous IP with Curl PHP on Linux</title>
		<link>http://www.dijexi.com/2010/06/how-to-use-tor-project-anonymous-ip-with-curl-php-on-linux/</link>
		<comments>http://www.dijexi.com/2010/06/how-to-use-tor-project-anonymous-ip-with-curl-php-on-linux/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 23:38:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[browsing anonymously]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[hide ip]]></category>
		<category><![CDATA[Tor]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2010/06/how-to-use-tor-project-anonymous-ip-with-curl-php-on-linux/</guid>
		<description><![CDATA[This article explains how to utilize Tor project in our own PHP application using Curl Library. Tor is free software and an open network that helps you defend against a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security known as traffic analysis. We start by [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>This article explains how to utilize <a href="http://www.torproject.org/" target="_blank">Tor project</a> in our own PHP application using Curl Library. </p>
<p>Tor is free software and an open network that helps you defend against a form of network surveillance that threatens personal freedom and privacy, confidential business activities and relationships, and state security known as traffic analysis. </p>
<p>We start by installing and configuring Tor and the necessary software then we create a simple application that fetch a website address anonymously.</p>
<p> <span id="more-1321"></span><br />
<h3>Download and Install Tor</h3>
<p>First thing, we need to download and install Tor application into our system. Click the <a href="http://www.torproject.org/easy-download.html.en" target="_blank">download page</a> to get the correct software for you, either Windows, Apple, or Linux bundle. In this example I use Linux system so I choose Linux.</p>
<p>My system use Debian etch, so I simply use apt-get to install it. But I need to configure my /etc/apt/source.list:</p>
<pre>deb     http://deb.torproject.org/torproject.org etch main</pre>
<p>Then I add the gpg key used to sign the packages by running the following commands at the command prompt: </p>
<pre>gpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | sudo apt-key add -</pre>
<p>&#160;</p>
<p>I refresh my sources and install Tor by running the following commands at the command prompt:&#160; </p>
<pre>apt-get update
apt-get install tor tor-geoipdb</pre>
<p>&#160;</p>
<h3>Install Polipo </h3>
<p>For TOR to run well we need at least Polipo version 1.0.4. Debian etch package for polipo is still on version === so I need to download the source code from <a href="http://www.pps.jussieu.fr/~jch/software/polipo/">Polipo&#160; website</a>. I put the source code at /usr/src/polipo-1.0.4.</p>
<p>I need to compile Polipo by typing make at the command prompt. </p>
<blockquote>
<p><font size="2" face="Courier New">cd /usr/src/polipo-1.0.4/<br />
      <br /></font><font size="2" face="Courier New">make</font></p>
</blockquote>
<p>When successful we will get polipo executable on that directory. We can place it&#160; on /opt/polipo directory or whichever you like.</p>
<p>Before running polipo <b>we will need to configure Polipo to use Tor</b>. Grab the <a href="https://svn.torproject.org/svn/torbrowser/trunk/build-scripts/config/polipo.conf">Polipo&#160; configuration for Tor</a> and put it in place of your current polipo config file (e.g. /etc/polipo/config or ~/.polipo). Then we run polipo to use that configuration file: </p>
<blockquote>
<p><font size="2" face="Courier New">/opt/polipo/polipo -c /etc/polipo/config&#160; daemonise=true&#160; logFile=&quot;/var/log/polipo.log&quot;</font></p>
</blockquote>
<p>On that command, I run polipo with config file located at /etc/polipo/config in daemon&#160; mode and with a log file. Later you can put this line at /etc/rc.local to run polipo automatically on system start. </p>
<h3>Configure Application to use TOR </h3>
<p>After successfully installing Tor and Polipo, we need to configure our applications to use them.&#160; </p>
<p>For PHP CURL library we need to add an option to Curl to use a HTTP Proxy to access&#160; the internet. The option is CURLOPT_PROXY which contains the Proxy address and port. This proxy address is our Polipo proxy server, which is located at 127.0.0.1 on port 8118. </p>
<p>Here is an example code.</p>
<pre>&lt;? $url = 'http://www.foo.bar/curl_receive_vars.html'; <font size="2" face="Courier New">$postfields = array ('username' =&gt; 'Myname',    'emailaddress' =&gt; </font><a href="mailto:'myaddress@foo.bar'"><font size="2" face="Courier New">'myaddress@foo.bar'</font></a><font size="2" face="Courier New">);
if (!$curld = curl_init()) {
    echo &quot;Could not initialize cURL session.\n&quot;;
    exit;
} 

/* Prepare for the POST operation. */
curl_setopt($curld, CURLOPT_POST, true);

/* Give cURL the variable names &amp; values to POST. */
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields);

/* The URL to which to POST the data. */
curl_setopt($curld, CURLOPT_URL, $url);

/* Indicate that we want the output returned into a variable. */
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true); </font><font size="2" face="Courier New">/* Set the proxy to our Polipo. */  </font><strong><font size="2" face="Courier New">curl_setopt($curld, CURLOPT_PROXY, &quot;http://127.0.0.1:8118/&quot;);</font></strong><strong><font size="2" face="Courier New"></font></strong><font size="2" face="Courier New">/* Do it. */
$output = curl_exec($curld);

echo &quot;Received data: &lt;hr&gt;$output&lt;hr&gt;\n&quot;;

/* Clean up. */
 curl_close($curld); </font><font size="2" face="Courier New"> ?&gt;
 </font></pre>
<p>The above code will fetch data from URL specified but the server will not know our real IP but the IP addresses of the Tor networks instead.</p>
<h3>Additional Step&#160; </h3>
<p>Set up Tor on web browser. </p>
<p>You should use Tor with Firefox and Torbutton, for best safety. Simply install the <a href="https://addons.mozilla.org/firefox/2275/">Torbutton plugin</a>, restart your Firefox, and you&#8217;re all set:&#160; </p>
<p><img border="1" alt="Torbutton plugin for Firefox" src="http://www.torproject.org/img/screenshot-torbutton.png" width="161" height="78" />&#160;</p>
<p>After that you can browse the internet using Firefox anonymously. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c6595ea0-cde3-48fa-ad0b-32b5456f55d3" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/tor" rel="tag">tor</a>,<a href="http://technorati.com/tags/linux" rel="tag">linux</a>,<a href="http://technorati.com/tags/ubuntu" rel="tag">ubuntu</a>,<a href="http://technorati.com/tags/debian" rel="tag">debian</a>,<a href="http://technorati.com/tags/php" rel="tag">php</a>,<a href="http://technorati.com/tags/hide+ip" rel="tag">hide ip</a>,<a href="http://technorati.com/tags/browsing+anonymously" rel="tag">browsing anonymously</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/how-to-browse-internet-anonymously/" rel="bookmark">How To Browse Internet Anonymously</a></li><li><a href="http://www.dijexi.com/2011/07/how-to-import-existing-project-directory-into-svn-repository/" rel="bookmark">How to Import Existing Project Directory Into SVN Repository</a></li><li><a href="http://www.dijexi.com/2010/08/how-to-install-asterisk-1-6-on-ubuntu/" rel="bookmark">How to install Asterisk 1.6 on Ubuntu</a></li><li><a href="http://www.dijexi.com/2009/07/lowongan-kerja-junior-programmer-dan-senior-web-programmer/" rel="bookmark">Lowongan Kerja : Junior Programmer dan Senior Web Programmer</a></li><li><a href="http://www.dijexi.com/2009/06/how-to-change-upload-file-size-on-a-windows-localhost/" rel="bookmark">How to change upload file size on a Windows localhost</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2010%2F06%2Fhow-to-use-tor-project-anonymous-ip-with-curl-php-on-linux%2F&amp;linkname=How%20to%20Use%20Tor%20Project%20Anonymous%20IP%20with%20Curl%20PHP%20on%20Linux"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2010/06/how-to-use-tor-project-anonymous-ip-with-curl-php-on-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</title>
		<link>http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/</link>
		<comments>http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/#comments</comments>
		<pubDate>Tue, 04 May 2010 02:31:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[accounting system]]></category>
		<category><![CDATA[main controller]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/</guid>
		<description><![CDATA[Well I’m sorry, it’s been so long for this part to come.. I had been working very hard on some clients and don’t have enough time to write. Here’s what I had been done if you’re curious :) : http://maps.GpsTrackingIndonesia.com, www.SunberryCorp.com, www.mypushme.com, www.kulacak.com, www.web2trace.com, www.pushmeportal.com, … The fun is almost all of them was written [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Well I’m sorry, it’s been so long for this part to come.. I had been working very hard on some clients and don’t have enough time to write. Here’s what I had been done if you’re curious :) : <a href="http://maps.GpsTrackingIndonesia.com">http://maps.GpsTrackingIndonesia.com</a>, <a href="http://www.SunberryCorp.com">www.SunberryCorp.com</a>, <a href="http://www.mypushme.com">www.mypushme.com</a>, <a href="http://www.kulacak.com">www.kulacak.com</a>, <a href="http://www.web2trace.com">www.web2trace.com</a>, <a href="http://www.pushmeportal.com">www.pushmeportal.com</a>, … The fun is almost all of them was written with CodeIgniter :).</p>
<p>Ok, let’s start with the easiest one first. We will create a simple menu page that contains links to other modules on the system. We put it on the Mainpage controller class. </p>
<p>Look at the Mainpage.php controller file. There is a function on it named exactly the same with the filename: Mainpage(). This should be exactly the same including the case. This is the constructor or initialization function of the class. Each time the class is called or instantiate, this function is called automatically. We put some initialization lines inside it:</p>
<p> <span id="more-1317"></span>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> Mainpage<span class="br0">&#40;</span><span class="br0">&#41;</span>&nbsp;<br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;parent::<span class="me2">Controller</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp; <br />
&nbsp; &nbsp; &nbsp;<span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">helper</span><span class="br0">&#40;</span><span class="st0">&#8216;url&#8217;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
<p>The line <strong>parent::Controller() </strong>calls the constructor function of this class’s parent constructor which is the CodeIgniter’s Controller class so that it has all the properties and method of it’s parent.</p>
<p>Then, we load a helper library that contains helper functions related to URL handling such as site_url() to return the site’s URL that we are working on. Other functions on this helper are: anchor(), base_url(), uri_string(), etc. You can check it all on the user guide <a title="http://localhost/acct/user_guide/helpers/url_helper.html" href="http://localhost/user_guide/helpers/url_helper.html">http://localhost/user_guide/helpers/url_helper.html</a>.</p>
<p>Again, look at the Mainpage.php file. We added a new function called <strong>index()</strong>. This function is analogous to the index.html file in static web page. It’s called by default when we point our browser to the Mainpage controller, ie: <a href="http://localhost/index.php/Mainpage">http://localhost/index.php/Mainpage</a>.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">public</span> <span class="kw2">function</span> index<span class="br0">&#40;</span><span class="br0">&#41;</span> <br />
<span class="br0">&#123;</span> <br />
&nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">view</span><span class="br0">&#40;</span><span class="st0">&#8216;header&#8217;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">view</span><span class="br0">&#40;</span><span class="st0">&quot;main_menu&quot;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">view</span><span class="br0">&#40;</span><span class="st0">&#8216;footer&#8217;</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; <span class="kw1">return</span>; <br />
<span class="br0">&#125;</span></div>
<p>On the function, we load view files. Here we divide the view into 3 pieces: header, main_menu, and footer. They are basically just regular PHP files dealing with display templates. This will make us easier to manage the look of our application later.</p>
<p>All of the view files should be located under <strong>system/application/views</strong> folder on CodeIgniter file structure. So we need to create all of them:</p>
<p>The <strong>header.php</strong> view file, contains the opening HTML tags, HEAD, TITLE and start of BODY. Later we can add CSS link definition here: </p>
<div class="dean_ch" style="white-space: wrap;">&lt;p&gt;&lt;!DOCTYPE HTML <span class="kw2">PUBLIC</span> <span class="st0">&quot;-//W3C//DTD HTML 3.2 Final//EN&quot;</span>&gt;</p>
<p>&lt;html&gt; &nbsp;<br />
&lt;head&gt;&lt;/p&gt;&lt;p&gt;&lt;title&gt;Cashbook application&lt;/title&gt; <br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;/p&gt;</div>
<p>&#160;</p>
<p>The <strong>footer.php</strong> view file, just a closing BODY and HTML tag, but you can later add your copyright notice, timestamps, etc:&#160;&#160; </p>
<p>&#160;</p>
<pre>&lt;/body&gt;
&lt;/html&gt;</pre>
<p>And the <strong>main_menu.php</strong> view file. Here we write a list of links to modules that we are going to develop later:</p>
<div class="dean_ch" style="white-space: wrap;">&lt;p&gt;&lt;p&gt;Cash Book&lt;/p&gt;</p>
<p>&lt;ul&gt;</p>
<p>&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Cashbook/addNew/receive&quot;</span>,<span class="st0">&quot;Cash Receive Entry&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span> &nbsp;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Cashbook/addNew/out&quot;</span>,<span class="st0">&quot;Cash Out Entry&quot;</span><span class="br0">&#41;</span> <span class="kw2">?&gt;</span></p>
<p>&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Cashbook/viewReport&quot;</span>,<span class="st0">&quot;Cash Book Report&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span> &nbsp;<br />
&lt;/ul&gt; &lt;/p&gt;<br />
&lt;p&gt;&lt;p&gt;Bank Book&lt;/p&gt; &nbsp;<br />
&lt;ul&gt;</p>
<p>&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Bankbook/addNew/receive&quot;</span>,<span class="st0">&quot;Bank Receive Entry&quot;</span><span class="br0">&#41;</span>;?&gt;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Bankbook/addNew/out&quot;</span>,<span class="st0">&quot;Bank Out Entry&quot;</span><span class="br0">&#41;</span>;?&gt;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Bankbook/viewReport&quot;</span>,<span class="st0">&quot;Bank Book Report&quot;</span><span class="br0">&#41;</span>;?&gt;<br />
&lt;/ul&gt; &lt;/p&gt;</p>
<p>&lt;p&gt;&lt;p&gt;Manual Journal&lt;/p&gt; &nbsp;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Journal/addNew&quot;</span>,<span class="st0">&quot;Manual Journal Entry&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span><br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Journal/viewReport&quot;</span>,<span class="st0">&quot;Manual Journal Report&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span><br />
&lt;/ul&gt; &lt;/p&gt;<br />
&lt;p&gt;&lt;p&gt;Report&lt;/p&gt;<br />
&lt;ul&gt; &nbsp;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Mainpage/trialBalance&quot;</span>,<span class="st0">&quot;Trial Balance&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span></p>
<p>&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Mainpage/balanceSheet&quot;</span>,<span class="st0">&quot;Balance Sheet&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span> &nbsp;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Mainpage/profitLoss&quot;</span>,<span class="st0">&quot;Profit and Loss&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span></p>
<p>&lt;/ul&gt; &lt;/p&gt;</p>
<p>&lt;p&gt;&lt;p&gt;Posting and COA&lt;/p&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Mainpage/doPosting&quot;</span>,<span class="st0">&quot;Post transaction&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span><br />
&lt;li&gt;&lt;?=anchor<span class="br0">&#40;</span><span class="st0">&quot;Coa/listCoa&quot;</span>,<span class="st0">&quot;Chart of Account Setting&quot;</span><span class="br0">&#41;</span><span class="kw2">?&gt;</span><br />
&lt;/ul&gt;&lt;/p&gt;</div>
<p>As we can see above, we call a helper function anchor(). This function will create a standard HTML anchor link based on your local site URL. So for example, if we call it <strong>achor(“Mainpage/trialBalance”, “Trial Balance”)</strong> then it will return this string:</p>
<p>&lt;a href=”http://localhost/Mainpage/trialBalance”&gt; Trial Balance &lt;/a&gt;</p>
<p>assumed that you have configured your site URL as <a href="http://localhost/">http://localhost/</a> on the config.php file.</p>
<p>Now we can run our application by pointing the browser to <a href="http://localhost">http://localhost</a> and it should return something like the following:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2010/05/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2010/05/image_thumb.png" width="404" height="484" /></a> </p>
<p>Congratulation! </p>
<p>Next we will begin to code the COA module.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c2efec71-3808-442a-9518-d1db80ef5dca" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/codeigniter" rel="tag">codeigniter</a>,<a href="http://technorati.com/tags/main+controller" rel="tag">main controller</a>,<a href="http://technorati.com/tags/accounting+system" rel="tag">accounting system</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 2 The Application Specification and UML Diagrams</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 3 ER Diagram and Creating Database</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2010%2F05%2Fcodeigniter-tutorial-creating-accounting-application-part-5-the-mainpage%2F&amp;linkname=CodeIgniter%20Tutorial%3A%20%5BCreating%20Accounting%20Application%5D%20Part%205%20The%20Mainpage"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>NetBeans IDE 6.8 Released</title>
		<link>http://www.dijexi.com/2009/12/netbeans-ide-6-8-released/</link>
		<comments>http://www.dijexi.com/2009/12/netbeans-ide-6-8-released/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 03:39:45 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[IT News]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/12/netbeans-ide-6-8-released/</guid>
		<description><![CDATA[NetBeans™ IDE 6.8 offers best-in-class support for the entire Java™ Platform Enterprise Edition 6 specification and the Sun GlassFish™ Enterprise Server v3 platform. Simplify Java application development with Java EE 6 language features: less XML configuration and more POJO-like development; easily target and deploy to GlassFish v3. NetBeans IDE continues to be the tool of [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p><b>NetBeans™ IDE 6.8</b> offers best-in-class support for the <b>entire Java™ Platform Enterprise Edition 6 specification</b> and the <b>Sun GlassFish™ Enterprise Server v3 platform</b>. Simplify Java application development with Java EE 6 language features: less XML configuration and more POJO-like development; easily target and deploy to GlassFish v3. </p>
<p><b>NetBeans IDE</b> continues to be the tool of choice for top development languages, and this release includes new features and improved support for <b>PHP 5.3</b> and the <b>Symfony framework</b>, the latest <b>JavaFX™ SDK 1.2.1, C/C++, Ruby, Maven</b> and more. Integration with <b>Project Kenai</b>, a collaborative environment for hosting open-source projects, now offers full support for <b>JIRA</b>, as well as improved issue tracker integration. As always, the <b>NetBeans Platform</b> provides a rock-solid application framework that can save years of development time. </p>
<p>Supporting Java EE 6 improvements first, NetBeans IDE 6.8 boosts developer productivity and lets developers take advantage of today&#8217;s latest languages and platform features. </p>
<p>NetBeans IDE 6.8 is available in English, Brazilian-Portuguese, Japanese and Simplified Chinese. </p>
<p><a href="http://netbeans.org/downloads/index.html?cid=928534"><img alt="Get Tomorrow Today with NetBeans IDE 6.8!" src="http://netbeans.org/images_www/newsletter/6.8/header.jpg" width="675" height="153" /></a></p>
<p> <span id="more-1294"></span><br />
<h2>Release Highlights</h2>
<p>Java Enterprise Edition 6</p>
<ul>
<li>JavaServer™ Faces 2.0 for web interfaces and the ability to use EJB™ software in web applications </li>
<li>Java Persistence JPA 2.0 and RESTful web services support </li>
<li>Deployment, debugging and profiling with GlassFish v3 </li>
</ul>
<p>JavaServer Faces 2.0 (Facelets)</p>
<ul>
<li>Code completion, error hints, namespace completion, documentation popups, and tag auto-import for Facelets </li>
<li>Editor support for Facelets libraries, composite components, expression language </li>
</ul>
<p>JavaFX</p>
<ul>
<li>Support for JavaFX SDK 1.2.1 </li>
<li>Improved navigation, code completion, and editor hints </li>
</ul>
<p>PHP</p>
<ul>
<li>PHP 5.3 support </li>
<li>Symfony framework support </li>
</ul>
<p>Kenai.com: Connected Developer</p>
<ul>
<li>Full JIRA support </li>
<li>Improved issue tracker integration </li>
</ul>
<p>Maven</p>
<ul>
<li>Improved support for Java EE 6, Groovy, Scala projects </li>
<li>Customizable dependency exclusion in dependency graph </li>
</ul>
<p>Ruby</p>
<ul>
<li>Support for Rails 2.3.4 apps with dispatchers, JRuby 1.4, Ruby 1.9 debugging, RSpec 1.2.7 </li>
<li>Improved rename refactoring, type inference, and navigation </li>
</ul>
<p>C/C++</p>
<ul>
<li>Profiling: New Thread Microstates indicator and Thread Details view </li>
<li>Faster synchronization during remote development </li>
</ul>
<h2>Learn More</h2>
<ul>
<li><a href="http://netbeans.org/community/releases/68/">NetBeans IDE 6.8 Release Information</a></li>
<li><a href="http://netbeans.org/kb/index.html">NetBeans IDE 6.8 Tutorials and Videos</a></li>
<li><a href="http://platform.netbeans.org/">NetBeans Platform 6.8</a></li>
<li><a href="http://netbeans.org/community/index.html">NetBeans Community</a></li>
<li><a href="http://twitter.com/netbeans">NetBeans on Twitter</a></li>
<li><a href="http://planetnetbeans.org/">Planet NetBeans</a></li>
<li><a href="https://channelsun.sun.com/category/playlist?id=81">NetBeans on ChannelSun</a></li>
</ul>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:797a2db2-ac8b-4a7f-8d96-73eb544c29d5" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/netbeans" rel="tag">netbeans</a>,<a href="http://technorati.com/tags/ide" rel="tag">ide</a>,<a href="http://technorati.com/tags/java" rel="tag">java</a>,<a href="http://technorati.com/tags/Software+Development" rel="tag">Software Development</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/best-free-development-tools-and-editors-software/" rel="bookmark">Best Free Development Tools and Editors Software</a></li><li><a href="http://www.dijexi.com/2009/06/joomla-15-mengganti-footer/" rel="bookmark">Joomla 1.5: Mengganti Footer</a></li><li><a href="http://www.dijexi.com/2009/07/zero-day-vulnerability-hits-microsoft-directshow/" rel="bookmark">Zero Day Vulnerability Hits Microsoft DirectShow</a></li><li><a href="http://www.dijexi.com/2009/08/zend-studio-7-0-released/" rel="bookmark">Zend Studio 7.0 Released</a></li><li><a href="http://www.dijexi.com/2010/02/funambol-mobile-open-source-book-released/" rel="bookmark">Funambol Mobile Open Source Book Released</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F12%2Fnetbeans-ide-6-8-released%2F&amp;linkname=NetBeans%20IDE%206.8%20Released"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/12/netbeans-ide-6-8-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code</title>
		<link>http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/</link>
		<comments>http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 08:00:00 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Accounting Application]]></category>
		<category><![CDATA[Cashbook Module]]></category>
		<category><![CDATA[CodeIgniter tutorial]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/</guid>
		<description><![CDATA[Generate PHP Code After installing StarUML PHP 5 Code Generator Template , StarUML will have a capability to generate PHP template code based on the models we have defined before. But there’s a little hack to be done so that the naming of the file generated complies with CodeIgniter. These PHP template code files can [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><h2>Generate PHP Code</h2>
<p>After installing StarUML <a href="http://staruml.sourceforge.net/en/templates.php">PHP 5 Code Generator Template</a> , StarUML will have a capability to generate PHP template code based on the models we have defined before. But there’s a little hack to be done so that the naming of the file generated complies with CodeIgniter.</p>
<p>These PHP template code files can be used to simplify our jobs by not typing all class’ attributes and methods that we have done in the UML design and analysis phase.</p>
<p><span id="more-1220"></span></p>
<p>Now open and edit the template file for PHP 5 code generation, located at “C:\Program Files\StarUML\modules\staruml-generator\templates\PHP 5 Code Generator\template.cot”. Locate at around line 327:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:7fc28bbc-cf4b-48b2-8e53-d068865b0f57" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;">fileBegin(getTarget()+&quot;\\&quot;+current().Name+&quot;.class.php&quot;);</div>
</div>
<p>remove the .class extension and change it to</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:7dc1d31a-7efe-4030-b3a0-e8c96655ba1d" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;">fileBegin(getTarget()+&quot;\\&quot;+current().Name+&quot;.php&quot;);</div>
</div>
<p>Save the file. After editing the above line, PHP template file generated will have .php extension and not .class.php extension which is not suitable to be copied to CodeIgniter file structure.</p>
<p>Next we will generate the PHP template code. Open the UML diagram file. Click on “Tools – StarUML Generator..” menu.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUML.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP 5 template code generator from starUML" src="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUML_thumb.png" border="0" alt="PHP 5 template code generator from starUML" width="504" height="304" /></a></p>
<p>A new dialog will be shown where we can choose a template for code generation.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUMLstep2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP 5 template code generator from starUML step2" src="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUMLstep2_thumb.png" border="0" alt="PHP 5 template code generator from starUML step2" width="504" height="369" /></a></p>
<p>On the dialog, choose PHP 5 Code Generator. Click Next. A new dialog will be shown where we can choose the destination folder to save the generated files.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUMLstep3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP 5 template code generator from starUML step3" src="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUMLstep3_thumb.png" border="0" alt="PHP 5 template code generator from starUML step3" width="504" height="369" /></a></p>
<p>On the dialog, choose any folder you wish. Then click Next. A new dialog will be shown showing that the generation process is ready to run.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUMLstep4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP 5 template code generator from starUML step4" src="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratorfromstarUMLstep4_thumb.png" border="0" alt="PHP 5 template code generator from starUML step4" width="504" height="369" /></a></p>
<p>Click on Generate button to start the generation process. Wait a moment until the process is finished. When it was finished, we will have some PHP files that each related to our model and controller class diagram before.</p>
<p>After generating both model and controller template files, we can see them on the destination folder specified before, for example, mine is on “c:\temp” folder.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratedfromstarUML.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP 5 template code generated from starUML" src="http://www.dijexi.com/wp-content/uploads/2009/09/PHP5templatecodegeneratedfromstarUML_thumb.png" border="0" alt="PHP 5 template code generated from starUML" width="504" height="436" /></a></p>
<p>Next, we need to move or copy all model files to CodeIgniter “models” folder and all controller classes to CodeIgniter “controllers” folder. If you followed the instruction exactly as in this tutorial, the it would be at “C:\xampp\htdocs\acct\system\application” folder where you could find “models” and “controllers” folder inside.</p>
<p>Let’s take a look for the generated PHP template file for a model, for example Bankbook_model.php file:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:919771bd-26ed-4c53-ae55-8439561ff21f" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="kw2">class</span> Bankbook_model <span class="kw2">extends</span> Model <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="re0">$idbankbook</span>;</p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> get<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> getAll<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> addNew<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> addDetails<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> getDetails<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> sumTotal<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> getNewNumber<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> delete<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> posting<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> update<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> deleteDetails<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> updateDetails<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<p>As you can see, we already have a template for our CodeIgniter model that’s ready for us to code the scripts logic inside. It has all the attributes and methods exactly the same as we designed in the UML diagram.</p>
<p>As in the model class’ template, we could also see the controller class’ template. Let’s take a look at the Bankbook.php file for example which is for Bankbook controller class.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:20bd13b0-3074-473f-8e5b-0f5310c709d7" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span></p>
<p><span class="kw2">class</span> Bankbook <span class="kw2">extends</span> Controller <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> Bankbook<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> index<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> addNew<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> editForm<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> save<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> delete<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> viewReport<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> addDetail<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<p>Again we can see that we already have all attributes and methods exactly the same as defined in the UML diagram.</p>
<h2>Edit config.php</h2>
<p>Next, we need to edit our CodeIgniter configuration file to suit our application environment. Open and edit the file “system/application/config/config.php” and locate the line of:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b41502f8-9d91-4db3-b22b-8a69d1e6206e" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;base_url&#8217;</span><span class="br0">&#93;</span> &nbsp; &nbsp;= <span class="st0">&quot;http://example.com/&quot;</span>;</div>
</div>
<p>Change and modify the content of base_url configuration to your own server name, for example <a href="http://localhost/">http://localhost/</a> . Don’t forget to put a trailing forward slash (/) on it. This will be the reference of other CodeIgniter’s class for your server base URL, ie. for calling other web resources on your application like other controller, images, JavaScript files, CSS, etc.</p>
<h2>Edit database.php</h2>
<p>Next, we need to configure our database connectivity parameters to be used by the application. Open and edit the file “system/application/config/database.php” and locate these lines and adjust the parameters to suit your own MySQL database settings:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:b1985e70-bc02-4888-8df7-6bf7aa782aa3" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$db</span><span class="br0">&#91;</span><span class="st0">&#8216;default&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;hostname&#8217;</span><span class="br0">&#93;</span> = <span class="st0">&quot;localhost&quot;</span>;<br />
<span class="re0">$db</span><span class="br0">&#91;</span><span class="st0">&#8216;default&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;username&#8217;</span><span class="br0">&#93;</span> = <span class="st0">&quot;root&quot;</span>;<br />
<span class="re0">$db</span><span class="br0">&#91;</span><span class="st0">&#8216;default&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;password&#8217;</span><span class="br0">&#93;</span> = <span class="st0">&quot;&quot;</span>;<br />
<span class="re0">$db</span><span class="br0">&#91;</span><span class="st0">&#8216;default&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;database&#8217;</span><span class="br0">&#93;</span> = <span class="st0">&quot;acctdb&quot;</span>;<br />
<span class="re0">$db</span><span class="br0">&#91;</span><span class="st0">&#8216;default&#8217;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&#8216;dbdriver&#8217;</span><span class="br0">&#93;</span> = <span class="st0">&quot;mysql&quot;</span>;</div>
</div>
<h2>Edit routes.php</h2>
<p>Next, we need to configure the default controller for our application. By default, this controller is called “welcome” and we can find the corresponding controller class file in “system/application/controller/welcome.php”. We need to change it to our main page called “Mainpage.php”.</p>
<p>Open and edit the file “system/application/config/routes.php” and change the default_controller parameter like this.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:8fd13dae-f00f-483c-858d-3d0ed97db82c" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$route</span><span class="br0">&#91;</span><span class="st0">&#8216;default_controller&#8217;</span><span class="br0">&#93;</span> = <span class="st0">&quot;Mainpage&quot;</span>;</div>
</div>
<p>At this point you should be able to access your controller class from browser even though it still do nothing but a blank page.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/Starttorunadefinedcodeignitercontrollerclass.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Start to run a defined codeigniter controller class" src="http://www.dijexi.com/wp-content/uploads/2009/09/Starttorunadefinedcodeignitercontrollerclass_thumb.png" border="0" alt="Start to run a defined codeigniter controller class" width="504" height="327" /></a></p>
<p>In this case, a blank page is all right, because we have not defined anything inside the controller methods (index() method in this case). Compare this to access an undefined controller class, for example ‘bank’ controller, that will result a Page not Found error message like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/09/Starttorunaundefinedcodeignitercontrollerclass.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Start to run a undefined codeigniter controller class" src="http://www.dijexi.com/wp-content/uploads/2009/09/Starttorunaundefinedcodeignitercontrollerclass_thumb.png" border="0" alt="Start to run a undefined codeigniter controller class" width="504" height="350" /></a></p>
<p>Try to access other controller classes like cashbook, coa, mainpage, etc. All of them should return a blank page and not any error messages.</p>
<p>In the next step, we will start  to code the logics inside each controller and model classes’ methods based on the specification and user requirement.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b31d0737-af6c-4ddf-9675-9eff07f139dc" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/CodeIgniter+Tutorial">CodeIgniter Tutorial</a>,<a rel="tag" href="http://technorati.com/tags/Accounting+Application">Accounting Application</a>,<a rel="tag" href="http://technorati.com/tags/Cashbook+Module">Cashbook Module</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 2 The Application Specification and UML Diagrams</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 3 ER Diagram and Creating Database</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li></ul></div><!--INFOLINKS_OFF--><p style="text-align: center;"><script type="text/javascript"><!--
google_ad_client = "pub-7773800616131770";
/* horizontal */
google_ad_slot = "1931057994";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F09%2Fcodeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code%2F&amp;linkname=CodeIgniter%20Tutorial%3A%20%5BCreating%20Accounting%20Application%5D%20Part%204%20Preparing%20to%20Code"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>How To Use CodeIgniter Pagination Class with Database</title>
		<link>http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/</link>
		<comments>http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 01:52:00 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter pagination class]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/</guid>
		<description><![CDATA[Pagination class is very useful when we are handling a very large set of data. With it, users can see a page of data sets for only 10 or 20 rows and provided with page navigation where user can go to the next and previous page or directly jump to a page number. CodeIgniter has [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Pagination class is very useful when we are handling a very large set of data. With it, users can see a page of data sets for only 10 or 20 rows and provided with page navigation where user can go to the next and previous page or directly jump to a page number. CodeIgniter has a class for doing this, but we must make a link to the data to be paginated to make it works correctly.</p>
<p>This article show you how to make the link between pagination class and database class to make the pagination works on a table that has a large set of data inside it.</p>
<p><span id="more-1189"></span></p>
<p>First, in your controller class, load the pagination class and the database class (if it was not automatically loaded by the the autoload.php configuration). In this example I use  a controller named Units that handle data from a table called units. It has 4 columns: id, name, imei, and owner.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:adba0d20-a8d7-4c9e-8ebb-b048abda25b0" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">class</span> Units <span class="kw2">extends</span> Controller <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">function</span> Units<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::<span class="me2">Controller</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">library</span><span class="br0">&#40;</span><span class="st0">&#8216;pagination&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
<p>Then at the index method of the class, first we read the value of the third segment of the URI which is the current offset number to a variable called $offset. If the segment is empty the we set the value as 0.</p>
<p>Then we do the query to the units table to retrieve it’s records. Before retrieving the records, we set the limit and offset by calling db-&gt;limit() method. Setting this will limit our query result only $limit records starting from record number $offset.</p>
<p>Next we set the configuration for the pagination class, which are the base_url that points to the current controller itself, total_rows that is the number of all rows of the table, and per_page that is the number of rows per page to display read by calling the db-&gt;count_all() method. Then we create the pagination links by calling the pagination-&gt;create_links() method.</p>
<p>Then we fill up an array variable $data that contains the $query result of the table and the $paginator links. After that, we pass the data to the view.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c4346400-4fcf-4789-a12d-3e075ea2c64f" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;">&nbsp; &nbsp; <span class="kw2">function</span> index<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$offset</span>=<span class="re0">$this</span>-&gt;<span class="me1">uri</span>-&gt;<span class="me1">segment</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$limit</span>=<span class="nu0">10</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">limit</span><span class="br0">&#40;</span><span class="re0">$limit</span>, <span class="re0">$offset</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$query</span> = <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&#8216;units&#8217;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;base_url&#8217;</span><span class="br0">&#93;</span> = site_url<span class="br0">&#40;</span><span class="br0">&#41;</span> . <span class="st0">&#8216;/units/index/&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;total_rows&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">count_all</span><span class="br0">&#40;</span><span class="st0">&#8216;units&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;per_page&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$limit</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">pagination</span>-&gt;<span class="me1">initialize</span><span class="br0">&#40;</span><span class="re0">$config</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$paginator</span>=<span class="re0">$this</span>-&gt;<span class="me1">pagination</span>-&gt;<span class="me1">create_links</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$data</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;query&#8217;</span> =&gt; <span class="re0">$query</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;paginator&#8217;</span>=&gt;<span class="re0">$paginator</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">view</span><span class="br0">&#40;</span><span class="st0">&#8216;units_index&#8217;</span>,<span class="re0">$data</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</div>
<p>In the view, we render the $query result into a table and print the pagination link at the bottom of the table.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:9d93fd3e-0046-4efa-b07d-bafb11b00012" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;">&lt;h3&gt;Master Data Units&lt;/h3&gt;<br />
&lt;a href=<span class="st0">&quot;&lt;?=site_url()?&gt;/units/add&quot;</span>&gt;create&lt;/a&gt;<br />
&lt;table id=<span class="st0">&quot;box-table-a&quot;</span>&gt;<br />
&lt;tr&gt;<br />
&nbsp; &nbsp; &lt;th&gt;&lt;/th&gt;<br />
&nbsp; &nbsp; &lt;th&gt;&lt;/th&gt;<br />
&nbsp; &nbsp; &lt;th&gt;Name&lt;/th&gt;<br />
&nbsp; &nbsp; &lt;th&gt;Imei&lt;/th&gt;<br />
&nbsp; &nbsp; &lt;th&gt;Owner&lt;/th&gt;<br />
&nbsp; &nbsp; &lt;th&gt;&lt;/th&gt;<br />
&lt;/tr&gt;<br />
<span class="kw2">&lt;?</span> <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$query</span>-&gt;<span class="me1">result</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">as</span> <span class="re0">$row</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw2">?&gt;</span><br />
&lt;tr&gt;<br />
&nbsp; &nbsp; &lt;td&gt;&lt;a href=<span class="st0">&quot;&lt;?=site_url()?&gt;/units/edit/&lt;?=$row-&gt;id?&gt;&quot;</span>&gt;Edit&lt;/a&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &lt;td&gt;&lt;a href=<span class="st0">&quot;&lt;?=site_url()?&gt;/units/delete/&lt;?=$row-&gt;id?&gt;&quot;</span>&gt;Delete&lt;/a&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &lt;td&gt;&lt;?=<span class="re0">$row</span>-&gt;<span class="me1">name</span>?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &lt;td&gt;&lt;?=<span class="re0">$row</span>-&gt;<span class="me1">imei</span>?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &lt;td&gt;&lt;?=<span class="re0">$row</span>-&gt;<span class="me1">owner</span>?&gt;&lt;/td&gt;<br />
&nbsp; &nbsp; &lt;td&gt;&lt;/td&gt;<br />
&lt;/tr&gt;</p>
<p><span class="kw2">&lt;?</span><span class="br0">&#125;</span><span class="kw2">?&gt;</span><br />
&lt;/table&gt;<br />
<span class="kw2">&lt;?</span>=<span class="re0">$paginator</span>?&gt;</div>
</div>
<p>Notice that in the view I put a link to create a new record that point to “units/add” URL. This is useful for adding new record and should be handled by other method in the units controller. Also I created links for deleting and editing each records, each pointing to “units/delete” and “units/edit”.</p>
<blockquote><p>Note: the above example is only for simplicity purpose. In the real world you should use model class to access to databases.</p></blockquote>
<p>Here is the complete list of our controller above:</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:486b1832-64b0-4876-a71f-d754d8913b21" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="kw2">class</span> Units <span class="kw2">extends</span> Controller <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">function</span> Units<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::<span class="me2">Controller</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">library</span><span class="br0">&#40;</span><span class="st0">&#8216;pagination&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">function</span> index<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$offset</span>=<span class="re0">$this</span>-&gt;<span class="me1">uri</span>-&gt;<span class="me1">segment</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$limit</span>=<span class="nu0">10</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">select</span><span class="br0">&#40;</span><span class="re0">$select</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">limit</span><span class="br0">&#40;</span><span class="re0">$limit</span>, <span class="re0">$offset</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$query</span> = <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&#8216;units&#8217;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;base_url&#8217;</span><span class="br0">&#93;</span> = site_url<span class="br0">&#40;</span><span class="br0">&#41;</span> . <span class="st0">&#8216;/units/index/&#8217;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;total_rows&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">count_all</span><span class="br0">&#40;</span><span class="st0">&#8216;units&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;per_page&#8217;</span><span class="br0">&#93;</span> = <span class="re0">$limit</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">pagination</span>-&gt;<span class="me1">initialize</span><span class="br0">&#40;</span><span class="re0">$config</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$paginator</span>=<span class="re0">$this</span>-&gt;<span class="me1">pagination</span>-&gt;<span class="me1">create_links</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$data</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;query&#8217;</span> =&gt; <span class="re0">$query</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&#8216;paginator&#8217;</span>=&gt;<span class="re0">$paginator</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">view</span><span class="br0">&#40;</span><span class="st0">&#8216;units_index&#8217;</span>,<span class="re0">$data</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<p>This is the screen shot of our controller called with <a href="http://localhost/index.php/units/index">http://localhost/index.php/units/index</a>.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/CodeIgniterPagination.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CodeIgniter Pagination" src="http://www.dijexi.com/wp-content/uploads/2009/08/CodeIgniterPagination_thumb.png" border="0" alt="CodeIgniter Pagination" width="504" height="428" /></a></p>
<p>And here is the URL if we click the second page <a title="http://localhost:8085/assets-v2/index.php/units/index/10" href="http://localhost/index.php/units/index/10">http://localhost/index.php/units/index/10</a> and the result.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/CodeIgniterPaginationPage2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CodeIgniter Pagination Page 2" src="http://www.dijexi.com/wp-content/uploads/2009/08/CodeIgniterPaginationPage2_thumb.png" border="0" alt="CodeIgniter Pagination Page 2" width="504" height="171" /></a></p>
<p>To make the table nice I used CSS table style from <a title="http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/" href="http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/">http://www.smashingmagazine.com/2008/08/13/top-10-css-table-designs/</a>.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:2bdc8955-4cf2-4740-be60-fbe6ae4f2b44" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/CodeIgniter+pagination+class">CodeIgniter pagination class</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code</a></li><li><a href="http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/" rel="bookmark">How to Mix Segment and Query String in CodeIgniter</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fhow-to-use-codeigniter-pagination-class-with-database%2F&amp;linkname=How%20To%20Use%20CodeIgniter%20Pagination%20Class%20with%20Database"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Library to Create Google Maps Encoded Polylines</title>
		<link>http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/</link>
		<comments>http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 08:44:41 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Google Map]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[CodeIgniter library]]></category>
		<category><![CDATA[Google Map polylines encoder]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/</guid>
		<description><![CDATA[This class is used to encode a number of coordinates into an encoded polylines to be used in Google Maps. The code is originally from Jim Hribar http://www.jimhribar.com/cgi-bin/moin.cgi/PolylineEncoder and is rewritten by Gabriel Svennerberg www.svennerberg.com into a class and modified by me into CodeIgniter library. The code is written using the methods and algorithms found [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>This class is used to encode a number of coordinates into an encoded polylines to be used in Google Maps. The code is originally from Jim Hribar <a href="http://www.jimhribar.com/cgi-bin/moin.cgi/PolylineEncoder">http://www.jimhribar.com/cgi-bin/moin.cgi/PolylineEncoder</a> and is rewritten by Gabriel Svennerberg <a href="http://www.svennerberg.com">www.svennerberg.com</a> into a class and modified by me into CodeIgniter library. The code is written using the methods and algorithms found in the work of Mark MacClure <a href="http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline">http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline</a></p>
<p><span id="more-1182"></span></p>
<p>To use the library, put the class file into system/application/library. Then load the library from your controller class. While loading the library, the only required argument is points which is an array containing the coordinates for the polyline. You can add additional parameters as described below.</p>
<p><strong>numLevels</strong> and <strong>zoomFactor</strong> are optional</p>
<p>This parameter defines how many different levels of magnification the polyline has and the change in magnification between those levels. Default values for these are</p>
<p>numLevels = 18<br />
zoomFactor = 2</p>
<p>Make sure to use the same numLevels and zoomFactor in your Javascript or the lines won&#8217;t display properly.</p>
<p><strong>verySmall</strong></p>
<p>This parameter indicates the length of a barely visible object at the highest zoom level. The default value is 0.00001. By lowering this number you can decrease the number of coordinates used.</p>
<p><strong>forceEndpoints</strong></p>
<p>This parameter indicates whether or not the endpoints should be visible at all zoom levels. This parameter is optional with a default value of true.  Probably should stay true regardless.</p>
<p>After defining the required and optional parameter, we could call the main methods of the class to create the encoded polylines.</p>
<p>dpEncode()</p>
<p>The returns value of the method is an associative array with the encoded polyline:</p>
<p>array["Points"] = The encoded coordinates<br />
array["Levels"] = Encoded level<br />
array["PointsLiteral"] = The encoded coordinates as a literal<br />
array["NumLevels"] = Returns the value for NumLevels<br />
array["ZoomFactor"] = Returns the value for ZoomFactor</p>
<p>There is another method which returns an array with the supplied (unencoded) coordinates:</p>
<p>getPoints()</p>
<p>Here is an example of CI controller that uses the library.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:cf5d6b06-0735-44dc-9fe9-811c8e0b1f06" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="kw2">class</span> Mapservices <span class="kw2">extends</span> Controller <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> Mapservices<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::<span class="me2">Controller</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw2">function</span> gettrack<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$points</span>=<a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$query</span> = <span class="re0">$this</span>-&gt;<span class="me1">db</span>-&gt;<span class="me1">get</span><span class="br0">&#40;</span><span class="st0">&#8216;tracks&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$query</span>-&gt;<span class="me1">result</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">as</span> <span class="re0">$row</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$points</span><span class="br0">&#91;</span><span class="br0">&#93;</span>=<a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span>-&gt;<span class="me1">lat</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$row</span>-&gt;<span class="me1">lon</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">library</span><span class="br0">&#40;</span><span class="st0">&#8216;Gmaputils&#8217;</span>,<span class="re0">$points</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$a</span> = <span class="re0">$this</span>-&gt;<span class="me1">gmaputils</span>-&gt;<span class="me1">dpEncode</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$data</span><span class="br0">&#91;</span><span class="st0">&#8216;mapsapi&#8217;</span><span class="br0">&#93;</span>=<span class="st0">&quot;enter your maps api key&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$data</span><span class="br0">&#91;</span><span class="st0">&#8216;encodedPoints&#8217;</span><span class="br0">&#93;</span>=<span class="re0">$a</span><span class="br0">&#91;</span><span class="st0">&#8216;Points&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$data</span><span class="br0">&#91;</span><span class="st0">&#8216;encodedLevels&#8217;</span><span class="br0">&#93;</span>=<span class="re0">$a</span><span class="br0">&#91;</span><span class="st0">&#8216;Levels&#8217;</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">load</span>-&gt;<span class="me1">view</span><span class="br0">&#40;</span><span class="st0">&#8216;index&#8217;</span>, <span class="re0">$data</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<p>In the above example, I load $points array variable with an array of latitude and longitude values from a table called tracks. After filling up the array, I initialized the library with that array of points array as the parameter. Then I called the dpEncode() method and store the result into a temporary array $a. Lastly I loaded the view called index supplied with data of encoded polylines.</p>
<p>Here is an example of that view file to display the encoded polylines.</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:7a1feb97-9cd2-4501-a76a-11a0a3a67054" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;">&lt;head&gt;<br />
&lt;script src=<span class="st0">&quot;http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key=&lt;?=$mapsapi?&gt;&quot;</span> type=<span class="st0">&quot;text/javascript&quot;</span>&gt;&lt;/script&gt;<br />
&lt;script&gt;<br />
<span class="kw2">function</span> init<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw2">var</span> map = <span class="kw2">new</span> GMap2<span class="br0">&#40;</span>document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&#8216;map&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw2">var</span> indonesia = <span class="kw2">new</span> GLatLng<span class="br0">&#40;</span><span class="nu0">-0.615222552406841</span>,<span class="nu0">110.830078125</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; map.<span class="me1">setCenter</span><span class="br0">&#40;</span>indonesia, <span class="nu0">4</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; encodedPolyline = <span class="kw2">new</span> GPolyline.<span class="me1">fromEncoded</span><span class="br0">&#40;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; color: <span class="st0">&quot;#FF0000&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; weight: <span class="nu0">5</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; points: &lt;?=encodedPoints?&gt;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; levels: &lt;?=encodedLevels?&gt;,<br />
&nbsp; &nbsp; &nbsp; &nbsp; zoomFactor: <span class="nu0">2</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; numLevels: <span class="nu0">18</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; map.<span class="me1">addOverlay</span><span class="br0">&#40;</span>encodedPolyline<span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span><br />
&lt;/script&gt;<br />
&lt;/head&gt;<br />
&lt;body <span class="kw3">onload</span>=<span class="st0">&quot;init()&quot;</span>&gt;<br />
&nbsp; &nbsp; &lt;div id=<span class="st0">&quot;map&quot;</span>&gt;&lt;/div&gt;<br />
&lt;/body&gt;</div>
</div>
<p>Here is the library code</p>
<div id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f2c0a958-1b19-42b8-bec1-448cbc07fa49" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span> <span class="kw1">if</span> <span class="br0">&#40;</span>!<a href="http://www.php.net/defined"><span class="kw3">defined</span></a><span class="br0">&#40;</span><span class="st0">&#8216;BASEPATH&#8217;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <a href="http://www.php.net/exit"><span class="kw3">exit</span></a><span class="br0">&#40;</span><span class="st0">&#8216;No direct script access allowed&#8217;</span><span class="br0">&#41;</span>;</p>
<p><span class="coMULTI">/**<br />
&nbsp;* Google Maps Polylines Library for Code Igniter<br />
&nbsp;* Written by Akhmad Daniel Sembiring<br />
&nbsp;* Copyright 2009<br />
&nbsp;* http://vitraining.com<br />
&nbsp;*<br />
&nbsp;* Released as free code, however,<br />
&nbsp;* You must keep the copyright information.<br />
&nbsp;*<br />
&nbsp;*<br />
&nbsp;* Version 1.0<br />
&nbsp;*/</span></p>
<p><span class="kw2">class</span> Gmaputils <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// The constructor</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> __construct<span class="br0">&#40;</span><a href="http://www.php.net/array"><span class="kw3">array</span></a> <span class="re0">$points</span>=<a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="br0">&#41;</span>, <span class="re0">$numLevels</span> = <span class="nu0">18</span>, <span class="re0">$zoomFactor</span> = <span class="nu0">2</span>, <span class="re0">$verySmall</span> = <span class="nu0">0.000001</span>, <span class="re0">$forceEndpoints</span> = <span class="kw2">true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">points</span> = <span class="re0">$points</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">numLevels</span> = <span class="re0">$numLevels</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">zoomFactor</span> = <span class="re0">$zoomFactor</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">verySmall</span> = <span class="re0">$verySmall</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">forceEndpoints</span> = <span class="re0">$forceEndpoints</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span> = <span class="nu0">0</span>; <span class="re0">$i</span> &lt; <span class="re0">$this</span>-&gt;<span class="me1">numLevels</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$this</span>-&gt;<span class="me1">zoomLevelBreaks</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span> = <span class="re0">$this</span>-&gt;<span class="me1">verySmall*</span><a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">zoomFactor</span>, <span class="re0">$this</span>-&gt;<span class="me1">numLevels</span>-<span class="re0">$i</span><span class="nu0">-1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <span class="re0">$points</span>;<br />
&nbsp; &nbsp; protected <span class="re0">$numLevels</span>;<br />
&nbsp; &nbsp; protected <span class="re0">$zoomFactor</span>;<br />
&nbsp; &nbsp; protected <span class="re0">$verySmall</span>;<br />
&nbsp; &nbsp; protected <span class="re0">$forceEndpoints</span>;<br />
&nbsp; &nbsp; protected <span class="re0">$zoomLevelBreaks</span>;</p>
<p>&nbsp; &nbsp; <span class="co1">// Returns the supplied coordinates</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> getPoints<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$this</span>-&gt;<span class="me1">points</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="co1">// The main method which is called to perform the encoding</span><br />
&nbsp; &nbsp; <span class="co1">// Returns an associative array containing the encoded points, levels,</span><br />
&nbsp; &nbsp; <span class="co1">// an escaped string literal containing the encoded points</span><br />
&nbsp; &nbsp; <span class="co1">// It also returns the zoomFactor and numLevels</span><br />
&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">function</span> dpEncode<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">////daniel</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dists</span>=<span class="st0">&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$absMaxDist</span> = <span class="st0">&#8221;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">points</span><span class="br0">&#41;</span> &gt; <span class="nu0">2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$stack</span><span class="br0">&#91;</span><span class="br0">&#93;</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="nu0">0</span>, <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">points</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span><span class="br0">&#40;</span><a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$stack</span><span class="br0">&#41;</span> &gt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$current</span> = <a href="http://www.php.net/array_pop"><span class="kw3">array_pop</span></a><span class="br0">&#40;</span><span class="re0">$stack</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$maxDist</span> = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$absMaxDist</span> = <span class="nu0">0</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span> = <span class="re0">$current</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="nu0">+1</span>; <span class="re0">$i</span> &lt; <span class="re0">$current</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$temp</span> = self::<span class="me2">distance</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">points</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span>, <span class="re0">$this</span>-&gt;<span class="me1">points</span><span class="br0">&#91;</span><span class="re0">$current</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#93;</span>, <span class="re0">$this</span>-&gt;<span class="me1">points</span><span class="br0">&#91;</span><span class="re0">$current</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$temp</span> &gt; <span class="re0">$maxDist</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$maxDist</span> = <span class="re0">$temp</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$maxLoc</span> = <span class="re0">$i</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$maxDist</span> &gt; <span class="re0">$absMaxDist</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$absMaxDist</span> = <span class="re0">$maxDist</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$maxDist</span> &gt; <span class="re0">$this</span>-&gt;<span class="me1">verySmall</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dists</span><span class="br0">&#91;</span><span class="re0">$maxLoc</span><span class="br0">&#93;</span> = <span class="re0">$maxDist</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array_push"><span class="kw3">array_push</span></a><span class="br0">&#40;</span><span class="re0">$stack</span>, <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$current</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>, <span class="re0">$maxLoc</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/array_push"><span class="kw3">array_push</span></a><span class="br0">&#40;</span><span class="re0">$stack</span>, <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="re0">$maxLoc</span>, <span class="re0">$current</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encodedPoints</span> = self::<span class="me2">createEncodings</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">points</span>, <span class="re0">$dists</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encodedLevels</span> = self::<span class="me2">encodeLevels</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">points</span>, <span class="re0">$dists</span>, <span class="re0">$absMaxDist</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encodedPointsLiteral</span> = <a href="http://www.php.net/str_replace"><span class="kw3">str_replace</span></a><span class="br0">&#40;</span><span class="st0">&#8216;<span class="es0">\\</span>&#8216;</span>,<span class="st0">&quot;<span class="es0">\\</span><span class="es0">\\</span>&quot;</span>,<span class="re0">$encodedPoints</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$polyline</span><span class="br0">&#91;</span><span class="st0">&quot;Points&quot;</span><span class="br0">&#93;</span> = <span class="re0">$encodedPoints</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$polyline</span><span class="br0">&#91;</span><span class="st0">&quot;Levels&quot;</span><span class="br0">&#93;</span> = <span class="re0">$encodedLevels</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$polyline</span><span class="br0">&#91;</span><span class="st0">&quot;PointsLiteral&quot;</span><span class="br0">&#93;</span> = <span class="re0">$encodedPointsLiteral</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$polyline</span><span class="br0">&#91;</span><span class="st0">&quot;ZoomFactor&quot;</span><span class="br0">&#93;</span> = <span class="re0">$this</span>-&gt;<span class="me1">zoomFactor</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$polyline</span><span class="br0">&#91;</span><span class="st0">&quot;NumLevels&quot;</span><span class="br0">&#93;</span> = <span class="re0">$this</span>-&gt;<span class="me1">numLevels</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$polyline</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <span class="kw2">function</span> computeLevel<span class="br0">&#40;</span><span class="re0">$dd</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$dd</span> &gt; <span class="re0">$this</span>-&gt;<span class="me1">verySmall</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$lev</span> = <span class="nu0">0</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$dd</span> &lt; <span class="re0">$this</span>-&gt;<span class="me1">zoomLevelBreaks</span><span class="br0">&#91;</span><span class="re0">$lev</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$lev</span>++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$lev</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <span class="kw2">function</span> distance<span class="br0">&#40;</span><span class="re0">$p0</span>, <span class="re0">$p1</span>, <span class="re0">$p2</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> == <span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> &amp;amp;&amp;amp; <span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> == <span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$out</span> = <a href="http://www.php.net/sqrt"><span class="kw3">sqrt</span></a><span class="br0">&#40;</span><a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span> + <a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$u</span> = <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>*<span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span> + <span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span> * <span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> / <span class="br0">&#40;</span><a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span> + <a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$u</span> &lt;= <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$out</span> = <a href="http://www.php.net/sqrt"><span class="kw3">sqrt</span></a><span class="br0">&#40;</span><a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> &#8211; <span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span> + <a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> &#8211; <span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$u</span> &gt;= <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$out</span> = <a href="http://www.php.net/sqrt"><span class="kw3">sqrt</span></a><span class="br0">&#40;</span><a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> &#8211; <span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span> + <a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span> &#8211; <span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>,<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="nu0">0</span> &lt; <span class="re0">$u</span> &amp;amp;&amp;amp; <span class="re0">$u</span> &lt; <span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$out</span> = <a href="http://www.php.net/sqrt"><span class="kw3">sqrt</span></a><span class="br0">&#40;</span><a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$u</span>*<span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span><span class="br0">&#41;</span>,<span class="nu0">2</span><span class="br0">&#41;</span> + <a href="http://www.php.net/pow"><span class="kw3">pow</span></a><span class="br0">&#40;</span><span class="re0">$p0</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$u</span>*<span class="br0">&#40;</span><span class="re0">$p2</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>-<span class="re0">$p1</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span>,<span class="nu0">2</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$out</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <a href="http://www.php.net/static"><span class="kw3">static</span></a> <span class="kw2">function</span> encodeSignedNumber<span class="br0">&#40;</span><span class="re0">$num</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$sgn_num</span> = <span class="re0">$num</span> &lt;&lt; <span class="nu0">1</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$num</span> &lt; <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="re0">$sgn_num</span> = ~<span class="br0">&#40;</span><span class="re0">$sgn_num</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw1">return</span> self::<span class="me2">encodeNumber</span><span class="br0">&#40;</span><span class="re0">$sgn_num</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <a href="http://www.php.net/static"><span class="kw3">static</span></a> <span class="kw2">function</span> createEncodings<span class="br0">&#40;</span><span class="re0">$points</span>, <span class="re0">$dists</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$plat</span> = <span class="st0">&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$plng</span> = <span class="st0">&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_points</span> = <span class="st0">&quot;&quot;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>=<span class="nu0">0</span>; <span class="re0">$i</span>&lt;count<span class="br0">&#40;</span><span class="re0">$points</span><span class="br0">&#41;</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$dists</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span> || <span class="re0">$i</span> == <span class="nu0">0</span> || <span class="re0">$i</span> == <a href="http://www.php.net/count"><span class="kw3">count</span></a><span class="br0">&#40;</span><span class="re0">$points</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$point</span> = <span class="re0">$points</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$lat</span> = <span class="re0">$point</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$lng</span> = <span class="re0">$point</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$late5</span> = <a href="http://www.php.net/floor"><span class="kw3">floor</span></a><span class="br0">&#40;</span><span class="re0">$lat</span> * 1e5<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$lnge5</span> = <a href="http://www.php.net/floor"><span class="kw3">floor</span></a><span class="br0">&#40;</span><span class="re0">$lng</span> * 1e5<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dlat</span> = <span class="re0">$late5</span> &#8211; <span class="re0">$plat</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$dlng</span> = <span class="re0">$lnge5</span> &#8211; <span class="re0">$plng</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$plat</span> = <span class="re0">$late5</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$plng</span> = <span class="re0">$lnge5</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_points</span> .= self::<span class="me2">encodeSignedNumber</span><span class="br0">&#40;</span><span class="re0">$dlat</span><span class="br0">&#41;</span> . self::<span class="me2">encodeSignedNumber</span><span class="br0">&#40;</span><span class="re0">$dlng</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$encoded_points</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <span class="kw2">function</span> encodeLevels<span class="br0">&#40;</span><span class="re0">$points</span>, <span class="re0">$dists</span>, <span class="re0">$absMaxDist</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_levels</span> = <span class="st0">&quot;&quot;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">forceEndpoints</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_levels</span> .= self::<span class="me2">encodeNumber</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">numLevels</span><span class="nu0">-1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_levels</span> .= self::<span class="me2">encodeNumber</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">numLevels</span> &#8211; self::<span class="me2">computeLevel</span><span class="br0">&#40;</span><span class="re0">$absMaxDist</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="re0">$i</span>=<span class="nu0">1</span>; <span class="re0">$i</span>&lt;count<span class="br0">&#40;</span><span class="re0">$points</span><span class="br0">&#41;</span><span class="nu0">-1</span>; <span class="re0">$i</span>++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/isset"><span class="kw3">isset</span></a><span class="br0">&#40;</span><span class="re0">$dists</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_levels</span> .= self::<span class="me2">encodeNumber</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">numLevels</span> &#8211; self::<span class="me2">computeLevel</span><span class="br0">&#40;</span><span class="re0">$dists</span><span class="br0">&#91;</span><span class="re0">$i</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">forceEndpoints</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_levels</span> .= self::<span class="me2">encodeNumber</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">numLevels</span> <span class="nu0">-1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encoded_levels</span> .= self::<span class="me2">encodeNumber</span><span class="br0">&#40;</span><span class="re0">$this</span>-&gt;<span class="me1">numLevels</span> &#8211; self::<span class="me2">computeLevel</span><span class="br0">&#40;</span><span class="re0">$absMaxDist</span><span class="br0">&#41;</span><span class="nu0">-1</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$encoded_levels</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; protected <a href="http://www.php.net/static"><span class="kw3">static</span></a> <span class="kw2">function</span> encodeNumber<span class="br0">&#40;</span><span class="re0">$num</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encodeString</span> = <span class="st0">&quot;&quot;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">while</span><span class="br0">&#40;</span><span class="re0">$num</span> &gt;= 0&#215;20<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$nextValue</span> = <span class="br0">&#40;</span>0&#215;20 | <span class="br0">&#40;</span><span class="re0">$num</span> &amp;amp; 0x1f<span class="br0">&#41;</span><span class="br0">&#41;</span> + <span class="nu0">63</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encodeString</span> .= <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="re0">$nextValue</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$num</span> &gt;&gt;= <span class="nu0">5</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$finalValue</span> = <span class="re0">$num</span> + <span class="nu0">63</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$encodeString</span> .= <a href="http://www.php.net/chr"><span class="kw3">chr</span></a><span class="br0">&#40;</span><span class="re0">$finalValue</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$encodeString</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a0ad041b-969c-45ae-8e60-d29a3cba14f6" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/CodeIgniter+library">CodeIgniter library</a>,<a rel="tag" href="http://technorati.com/tags/Google+Map+polylines+encoder">Google Map polylines encoder</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li><li><a href="http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/" rel="bookmark">How To Use CodeIgniter Pagination Class with Database</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/" rel="bookmark">How to Mix Segment and Query String in CodeIgniter</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fcodeigniter-library-to-create-google-maps-encoded-polylines%2F&amp;linkname=CodeIgniter%20Library%20to%20Create%20Google%20Maps%20Encoded%20Polylines"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Mix Segment and Query String in CodeIgniter</title>
		<link>http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/</link>
		<comments>http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 03:30:53 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[query string]]></category>
		<category><![CDATA[segment]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/</guid>
		<description><![CDATA[Passing parameter to a web page build with CodeIgniter (CI) can be done by using either POST variables which comes from HTML form or from the URI. But, different from traditional web application, by default CI only recognizes a segment based URI rather than query string format for passing parameter by URI. In some circumstances [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Passing parameter to a web page build with CodeIgniter (CI) can be done by using either POST variables which comes from HTML form or from the URI. But, different from traditional web application, by default CI only recognizes a segment based URI rather than query string format for passing parameter by URI.</p>
<p>In some circumstances we do need to use the query string to pass data to our page, which in this case using PHP global variable $_GET. By default, CI will not allow us to read the content of $_GET variable but instead using the URI class $this-&gt;uri-&gt;segment(the_segment_number). </p>
<p> <span id="more-1181"></span>
<p>To be able to read the content of $_GET variable within a controller we need to do several things.</p>
<p>First, edit the system/application/config/config.php file, locate the line of uri_protocol configuration, and change the value to PATH_INFO.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:fc7cb530-0708-477d-95ea-96be773193f9" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$config</span><span class="br0">&#91;</span><span class="st0">&#8216;uri_protocol&#8217;</span><span class="br0">&#93;</span>&nbsp;= <span class="st0">&quot;PATH_INFO&quot;</span>;<br />
&nbsp;</div>
</div>
<p>Then, in the controller that we need to read the $_GET variable, put this line inside the controller class constructor.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4297f86e-d1b7-41c4-81ea-47d9a0fd7275" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/parse_str"><span class="kw3">parse_str</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;QUERY_STRING&#8217;</span><span class="br0">&#93;</span>,<span class="re0">$_GET</span><span class="br0">&#41;</span>;</div>
</div>
<p>After that, the controller will be able to read the content of the $_GET variable. For example, if we call the controller by using this URI server.com/index.php/controller/abcd?q=1234&amp;js=true, then we can read each of the parameter passed on the URI like this:</p>
<p>&#160;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:483c356d-556b-4201-a0ae-bb8f8b7dee4f" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;">$abcd=$this-&gt;uri-&gt;segment(3); // $abcd will contains &quot;abcd&quot;<br />
$q = $_GET['q'] ; // $q will contains &quot;1234&quot;<br />
$js = $_GET['js']; // $js will contains &quot;true&quot;<br />
&nbsp;</div>
</div>
<p>Here is an example of a controller class that can read both URI segment and query string.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:27d5d8ba-866a-4ad2-a4c5-9c671f467c3b" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?php</span><br />
<span class="kw2">class</span> Mapservices <span class="kw2">extends</span> Controller <span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="kw2">function</span> Mapservices<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::<span class="me2">Controller</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/parse_str"><span class="kw3">parse_str</span></a><span class="br0">&#40;</span><span class="re0">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#8216;QUERY_STRING&#8217;</span><span class="br0">&#93;</span>,<span class="re0">$_GET</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw2">function</span> lookup<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$table</span> = <span class="re0">$this</span>-&gt;<span class="me1">uri</span>-&gt;<span class="me1">segment</span><span class="br0">&#40;</span><span class="nu0">3</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$q</span>=<span class="re0">$_GET</span><span class="br0">&#91;</span><span class="st0">&#8216;q&#8217;</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// do the required process here&#8230;&nbsp; &nbsp; &nbsp; </span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><br />
<span class="kw2">?&gt;</span></div>
</div>
<p>On the above example, the controller called mapservices could be called by using this URI: server.com/index.php/mapservices/cities?q=bandung .</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:96a568db-bade-4c77-b644-69de1017b357" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/CodeIgniter" rel="tag">CodeIgniter</a>,<a href="http://technorati.com/tags/segment" rel="tag">segment</a>,<a href="http://technorati.com/tags/query+string" rel="tag">query string</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/08/how-to-use-codeigniter-pagination-class-with-database/" rel="bookmark">How To Use CodeIgniter Pagination Class with Database</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/" rel="bookmark">CodeIgniter Library to Create Google Maps Encoded Polylines</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fhow-to-mix-segment-and-query-string-in-codeigniter%2F&amp;linkname=How%20to%20Mix%20Segment%20and%20Query%20String%20in%20CodeIgniter"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Tutorial: [Creating Accounting Application] Part 3 ER Diagram and Creating Database</title>
		<link>http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/</link>
		<comments>http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 01:05:00 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[accounting system]]></category>
		<category><![CDATA[CodeIgniter tutorial]]></category>
		<category><![CDATA[ERD]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/</guid>
		<description><![CDATA[In the previous parts of this tutorial series we have discussed how to setup the application environment using XAMPP and CodeIgniter, and the application specification. We have done the analysis and design using UML use case and class diagram with free UML diagram tool StarUML. In this part, we will discuss the database design for [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>In the previous parts of this tutorial series we have discussed how to setup the application environment using XAMPP and CodeIgniter, and the application specification. We have done the analysis and design using <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML</a> use case and <a href="http://en.wikipedia.org/wiki/Class_diagram">class diagram</a> with free UML diagram tool <a href="http://staruml.sourceforge.net/en/">StarUML</a>. </p>
<p>In this part, we will discuss the database design for our application. This database is needed to hold the data for our application.</p>
<p>We are going to draw the entity relationship diagram (ERD) using a free tool called <a href="http://dev.mysql.com/downloads/workbench/5.1.html">MySQL workbench</a>, formerly <a href="http://www.fabforce.net/dbdesigner4/downloads.php">fabForce ERD tools</a> for MySQL. Before continuing, please <a href="http://dev.mysql.com/downloads/workbench/5.1.html" target="_blank">download the program here</a> and install it to your computer.</p>
<p>At the end of the designing process, we will create our database structure directly to a MySQL server that can be used by our application.</p>
<p> <span id="more-1160"></span><br />
<h2>The Tables </h2>
<p>For the purpose of our application requirements and based on UML use case we defined before, here is a list of mandatory tables that we must create on the application’s database.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Table name</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Purpose</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">coatype</td>
<td valign="top" width="250">store chart of account type data like assets, liability, equity, income, and cost</td>
</tr>
<tr>
<td valign="top" width="250">coa</td>
<td valign="top" width="250">store the actual chart of account data, should be multi level depth</td>
</tr>
<tr>
<td valign="top" width="250">cashbook</td>
<td valign="top" width="250">store the master cashbook document data</td>
</tr>
<tr>
<td valign="top" width="250">cashbook_detail</td>
<td valign="top" width="250">store the details cashbook document data</td>
</tr>
<tr>
<td valign="top" width="250">bankbook</td>
<td valign="top" width="250">store the master bankbook document data</td>
</tr>
<tr>
<td valign="top" width="250">bankbook_detail</td>
<td valign="top" width="250">store the details bankbook document data</td>
</tr>
<tr>
<td valign="top" width="250">journal</td>
<td valign="top" width="250">store the posted and unposted journal data for the purpose of accounting report generating process like balance sheet, income statement, and trial balance</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
<td valign="top" width="250">&#160;</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
<td valign="top" width="250">&#160;</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<h2>Creating Tables in MySQL Workbench</h2>
<p>Installing MySQL Workbench should not be a problem. I assumed that you already have done that. Now, run the program and you will see a blank workspace of MySQL model like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Blankmysqlmodelonmysqlworkbench.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blank mysql model on mysql workbench" border="0" alt="Blank mysql model on mysql workbench" src="http://www.dijexi.com/wp-content/uploads/2009/08/Blankmysqlmodelonmysqlworkbench_thumb.png" width="504" height="408" /></a> </p>
<p>Click on Add Diagram icon to create our first diagram. You will see a blank page for drawing our diagram like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Blankdiagramonmysqlworkbench.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Blank diagram on mysql workbench" border="0" alt="Blank diagram on mysql workbench" src="http://www.dijexi.com/wp-content/uploads/2009/08/Blankdiagramonmysqlworkbench_thumb.png" width="504" height="408" /></a> </p>
<h3>Creating A New Table and Adding Fields</h3>
<p>Next, we need to draw a table. Click on the “Place a New Table” located on the left side of the blank diagram. Then place it on the middle of the blank page. After placing the table, you may resize it’s size so that we can see a tall rectangular like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Placeanewtableonthepage.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Place a new table on the page" border="0" alt="Place a new table on the page" src="http://www.dijexi.com/wp-content/uploads/2009/08/Placeanewtableonthepage_thumb.png" width="366" height="456" /></a> </p>
<p>Double click on the table to add it’s columns. You will see a new pane at the bottom of the page consisting the table properties like this:</p>
<p>&#160;<a href="http://www.dijexi.com/wp-content/uploads/2009/08/Setthenewtablename.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Set the new table name" border="0" alt="Set the new table name" src="http://www.dijexi.com/wp-content/uploads/2009/08/Setthenewtablename_thumb.png" width="391" height="683" /></a> </p>
<p>On the pane, there’s a lot of tab on it’s bottom part. Click the “Table” where we can give our new table a name. Create our first table called “cashbook”. </p>
<p>Next we need to define the table columns. Click on the “Columns” tab. You will see the following:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Setthefirstcolumnasprimarykey.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Set the first column as primary key" border="0" alt="Set the first column as primary key" src="http://www.dijexi.com/wp-content/uploads/2009/08/Setthefirstcolumnasprimarykey_thumb.png" width="504" height="462" /></a> </p>
<p>As you can see, the program automatically add a column called “idcashbook” which you can rename it. This column should be the table’s primary key, so we check on the NN (means not null), AI (auto increment), and Flags PRIMARY KEY. When we set it up, then the icon left to the column name will change to a yellow key icon.</p>
<p>Next, we need to add more column. To do that, double click the empty row below the first column. Enter “trxdate” as the column name and DATETIME as the type. Your table property should be like the following:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Addinganewtablecolumn.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Adding a new table column" border="0" alt="Adding a new table column" src="http://www.dijexi.com/wp-content/uploads/2009/08/Addinganewtablecolumn_thumb.png" width="504" height="154" /></a> </p>
<p>Repeat the step of adding new field for the following new fields:</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Field Name</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Type</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">vounumber</td>
<td valign="top" width="250">VARCHAR(45)</td>
</tr>
<tr>
<td valign="top" width="250">doctype</td>
<td valign="top" width="250">VARCHAR(45)</td>
</tr>
<tr>
<td valign="top" width="250">amount</td>
<td valign="top" width="250">DECIMAL(20,2)</td>
</tr>
<tr>
<td valign="top" width="250">notes</td>
<td valign="top" width="250">VARCHAR(100)</td>
</tr>
<tr>
<td valign="top" width="250">posted</td>
<td valign="top" width="250">INT</td>
</tr>
</tbody>
</table>
<h3>Creating Other Tables </h3>
<p>Here is a list of tables with it’s description that we need to create for our application. Repeat the above steps to create every table listed below.</p>
<h4><u>Table cashbook (should have been created before) </u></h4>
<p>This is the master table of cashbook document. It has it’s detail records in cashbook_details table.</p>
<table border="0" cellspacing="0" cellpadding="2" width="503">
<tbody>
<tr>
<td valign="top" width="179">
<p align="center"><strong>Field Name</strong></p>
</td>
<td valign="top" width="174">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="148">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="179">idcashbook</td>
<td valign="top" width="174">INT (NOT NULL AI PK)</td>
<td valign="top" width="148">the table’s primary key, not null auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="179">vounumber</td>
<td valign="top" width="174">VARCHAR(45)</td>
<td valign="top" width="148">the cashbook document number</td>
</tr>
<tr>
<td valign="top" width="179">doctype</td>
<td valign="top" width="174">VARCHAR(45)</td>
<td valign="top" width="148">the document type (cash out or receive)</td>
</tr>
<tr>
<td valign="top" width="179">amount</td>
<td valign="top" width="174">DECIMAL(20,2)</td>
<td valign="top" width="148">the document amount </td>
</tr>
<tr>
<td valign="top" width="179">notes</td>
<td valign="top" width="174">VARCHAR(100)</td>
<td valign="top" width="148">additional notes</td>
</tr>
<tr>
<td valign="top" width="179">posted</td>
<td valign="top" width="188">INT</td>
<td valign="top" width="187">whether this document is posted (1) or not (0)</td>
</tr>
</tbody>
</table>
<h4><u>Table cashbook_detail</u></h4>
<p>This is the detail records of table cashbook.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="166">
<p align="center"><strong>Field Name</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="166">idcashbookdetail</td>
<td valign="top" width="166">INT (NOT NULL AI PK)</td>
<td valign="top" width="166">the table’s primary key, not null, auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="166">description</td>
<td valign="top" width="166">VARCHAR(100)</td>
<td valign="top" width="166">transaction description</td>
</tr>
<tr>
<td valign="top" width="166">amount</td>
<td valign="top" width="166">DECIMAL(20,2)</td>
<td valign="top" width="166">transaction amount</td>
</tr>
<tr>
<td valign="top" width="166">cashbook_idcashbook</td>
<td valign="top" width="166">INT NOT NULL (FK)</td>
<td valign="top" width="166">foreign key to cashbook table</td>
</tr>
</tbody>
</table>
<h4><u>Table bankbook</u></h4>
<p>This is the master table of bankbook document. It has it’s detail records in bankbook_details table.</p>
<table border="0" cellspacing="0" cellpadding="2" width="503">
<tbody>
<tr>
<td valign="top" width="179">
<p align="center"><strong>Field Name</strong></p>
</td>
<td valign="top" width="174">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="148">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="179">idbankbook</td>
<td valign="top" width="174">INT (NOT NULL AI PK)</td>
<td valign="top" width="148">the table’s primary key, not null auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="179">vounumber</td>
<td valign="top" width="174">VARCHAR(45)</td>
<td valign="top" width="148">the bankbook document number</td>
</tr>
<tr>
<td valign="top" width="179">doctype</td>
<td valign="top" width="174">VARCHAR(45)</td>
<td valign="top" width="148">the document type (bank out or receive)</td>
</tr>
<tr>
<td valign="top" width="179">amount</td>
<td valign="top" width="174">DECIMAL(20,2)</td>
<td valign="top" width="148">the document amount </td>
</tr>
<tr>
<td valign="top" width="179">notes</td>
<td valign="top" width="174">VARCHAR(100)</td>
<td valign="top" width="148">additional notes</td>
</tr>
<tr>
<td valign="top" width="179">posted</td>
<td valign="top" width="188">INT</td>
<td valign="top" width="187">whether this document is posted (1) or not (0)</td>
</tr>
<tr>
<td valign="top" width="179">coa_idcoa</td>
<td valign="top" width="188">INT NOT NULL (FK)</td>
<td valign="top" width="187">foreign key to coa table</td>
</tr>
</tbody>
</table>
<h4><u>Table bankbook_detail</u></h4>
<p>This is the detail records of table bankbook.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="166">
<p align="center"><strong>Field Name</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="166">idcashbookdetail</td>
<td valign="top" width="166">INT (NOT NULL AI PK)</td>
<td valign="top" width="166">the table’s primary key, not null, auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="166">description</td>
<td valign="top" width="166">VARCHAR(100)</td>
<td valign="top" width="166">transaction description</td>
</tr>
<tr>
<td valign="top" width="166">amount</td>
<td valign="top" width="166">DECIMAL(20,2)</td>
<td valign="top" width="166">transaction amount</td>
</tr>
<tr>
<td valign="top" width="166">cashbook_idcashbook</td>
<td valign="top" width="166">INT (FK)</td>
<td valign="top" width="166">foreign key to cashbook table</td>
</tr>
<tr>
<td valign="top" width="166">coa_idcoa</td>
<td valign="top" width="166">INT NOT NULL (FK)</td>
<td valign="top" width="166">foreign key to coa table</td>
</tr>
</tbody>
</table>
<h4>Table coa</h4>
<p>This table store the chart of account data. It will be referenced by cashbook_detail, bankbook_detail, and journal table.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="166">
<p align="center"><strong>Field Name</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="166">idcoa</td>
<td valign="top" width="166">INT (NOT NULL AI PK)</td>
<td valign="top" width="166">the table’s primary key, not null, auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="166">description</td>
<td valign="top" width="166">VARCHAR(100)</td>
<td valign="top" width="166">the account description</td>
</tr>
<tr>
<td valign="top" width="166">code</td>
<td valign="top" width="166">VARCHAR(45)</td>
<td valign="top" width="166">the account code</td>
</tr>
<tr>
<td valign="top" width="166">begin_balance</td>
<td valign="top" width="166">DECIMAL(20,2)</td>
<td valign="top" width="166">beginning balance of the account</td>
</tr>
<tr>
<td valign="top" width="166">isheader</td>
<td valign="top" width="166">INT</td>
<td valign="top" width="166">whether this account is a header account(1) or a detail account(0)</td>
</tr>
<tr>
<td valign="top" width="166">idparent</td>
<td valign="top" width="166">INT </td>
<td valign="top" width="166">link to other account to identify it’s parent in chart of account structure</td>
</tr>
<tr>
<td valign="top" width="166">link</td>
<td valign="top" width="166">VARCHAR(45)</td>
<td valign="top" width="166">link to usage information of this account, for example “cash” or “bank” account</td>
</tr>
<tr>
<td valign="top" width="166">coatype_idcoatype</td>
<td valign="top" width="166">INT NOT NULL (FK)</td>
<td valign="top" width="166">foreign key to coatype table to identify what kind of account is this</td>
</tr>
</tbody>
</table>
<h4><u>Table coatype</u></h4>
<p>This table store the COA type</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="166">
<p align="center"><strong>Name</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="166">idcoatype</td>
<td valign="top" width="166">INT (NOT NULL AI PK)</td>
<td valign="top" width="166">the table’s primary key, not null, auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="166">code</td>
<td valign="top" width="166">VARCHAR(45)</td>
<td valign="top" width="166">the account type code</td>
</tr>
<tr>
<td valign="top" width="166">description</td>
<td valign="top" width="166">VARCHAR(100)</td>
<td valign="top" width="166">the account type description</td>
</tr>
</tbody>
</table>
<h4><u>Table journal</u></h4>
<p>This table store journal transactions generated by cashbook and bankbook transaction after being posted and manual journal transaction entered manually.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="166">
<p align="center"><strong>Name</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Type</strong></p>
</td>
<td valign="top" width="166">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="166">idjournal</td>
<td valign="top" width="166">INT (NOT NULL AI PK)</td>
<td valign="top" width="166">the table’s primary key, not null, auto increment integer value</td>
</tr>
<tr>
<td valign="top" width="166">trxdate</td>
<td valign="top" width="166">DATETIME</td>
<td valign="top" width="166">transaction date</td>
</tr>
<tr>
<td valign="top" width="166">vounumber</td>
<td valign="top" width="166">VARCHAR(45)</td>
<td valign="top" width="166">the transaction document number</td>
</tr>
<tr>
<td valign="top" width="166">amount_db</td>
<td valign="top" width="166">DECIMAL(20,2)</td>
<td valign="top" width="166">debit amount</td>
</tr>
<tr>
<td valign="top" width="166">amount_cr</td>
<td valign="top" width="166">DECIMAL(20,2)</td>
<td valign="top" width="166">credit amount</td>
</tr>
<tr>
<td valign="top" width="166">description</td>
<td valign="top" width="166">VARCHAR(100)</td>
<td valign="top" width="166">transaction description</td>
</tr>
<tr>
<td valign="top" width="166">posted</td>
<td valign="top" width="166">INT</td>
<td valign="top" width="166">whether this transaction is posted (1) or not (0)</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<h2>Creating Relationships</h2>
<p>To create a relationship between two table in MySQL Workbench, simply click on the “Place a Relationship Using Existing Column” icon on the left side of the diagram. Then:</p>
<ol>
<li>set the FOREIGN KEY column on the referencing table, and </li>
<li>set the PRIMARY KEY column on the referenced table </li>
</ol>
<p>For example, to create a relationship between cashbook (the referenced table) and cashbook_detail (the referencing table): </p>
<p>1. Click “Place a Relationship Using Existing Column” icon </p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Step1creatingrelationship.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Step 1 creating relationship" border="0" alt="Step 1 creating relationship" src="http://www.dijexi.com/wp-content/uploads/2009/08/Step1creatingrelationship_thumb.png" width="271" height="563" /></a> </p>
<p>2. click cashbook_idcashbook column on the cashbook_detail table and click “Pick Referenced Column” button</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Step2creatingrelationship.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Step 2 creating relationship" border="0" alt="Step 2 creating relationship" src="http://www.dijexi.com/wp-content/uploads/2009/08/Step2creatingrelationship_thumb.png" width="458" height="546" /></a> </p>
<p>3. click idcashbook column on the cashbook table</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Step3creatingrelationship.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Step 3 creating relationship" border="0" alt="Step 3 creating relationship" src="http://www.dijexi.com/wp-content/uploads/2009/08/Step3creatingrelationship_thumb.png" width="464" height="544" /></a> </p>
<p>A relationship line will be drawn between those two tables.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/Step4creatingrelationship.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Step 4 creating relationship" border="0" alt="Step 4 creating relationship" src="http://www.dijexi.com/wp-content/uploads/2009/08/Step4creatingrelationship_thumb.png" width="307" height="539" /></a> </p>
<p>&#160;</p>
<h2>The Finished ER Diagram</h2>
<p>After you have created all the tables and relations as specified above, here is the completed ER diagram will looks like:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/ThecompletedERD.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="The completed ERD" border="0" alt="The completed ERD" src="http://www.dijexi.com/wp-content/uploads/2009/08/ThecompletedERD_thumb.png" width="520" height="422" /></a></p>
<p>And here is the diagram <a href="http://www.dijexi.com/wp-content/uploads/2009/08/erd-cashbank1.zip" target="_blank">MWB file for you to download</a>.</p>
<p>&#160;</p>
<h2>Creating the Database into MySQL Server</h2>
<p>After finishing the design of the ERD we need to create the database structure directly into MySQL server. To do this first we need to define the database server connection. Click on the menu Database – Manage Connections… You will see a dialog like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBcreateconnection.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB create connection" border="0" alt="MWB create connection" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBcreateconnection_thumb.png" width="504" height="316" /></a> </p>
<p>Click on New button and enter the Connection Name for example localhost, the Database System of MySQL, and the Driver of MySQL Native Driver. On the Parameters pane, enter your hostname or IP address on the Hostname field, Port number which is default to 3306, the Username and Password which match to your MySQL server configuration.</p>
<p>You may optionally click on Test Connection to make sure that the connection to the database server was successful. Click Close button.</p>
<p>To generate the database structure first we need to define the database name to be created. Click on the MySQL Model tab on the main page of MySQL Workbench. Then double click on mydb tab under Physical Schemata section. Look under the mydb property pane. Change the Name to the database name to be created, for example acctdb.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBdefinethedatabasename.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB define the database name" border="0" alt="MWB define the database name" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBdefinethedatabasename_thumb.png" width="400" height="715" /></a> </p>
<p>Don’t forget to click on Save Current Model icon to save our diagram.</p>
<p>Next, click on the menu Database – Forward Engineer.. to begin creating the database structure. A dialog box will appear:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB forward engineer step 1" border="0" alt="MWB forward engineer step 1" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep1_thumb.png" width="504" height="391" /></a> </p>
<p>Click Run Validations to make sure that the table definitions and relationship in our diagram was all correct. Then click on Next button. The next dialog box will appear:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB forward engineer step 2" border="0" alt="MWB forward engineer step 2" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep2_thumb.png" width="504" height="392" /></a>&#160; </p>
<p>On that dialog, you specify the options for creating the database. The first options is to drop objects before each CREATE Object, and the second is to generate separate CREATE INDEX statements. Then click on Next button. The next dialog box will appear:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB forward engineer step 3" border="0" alt="MWB forward engineer step 3" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep3_thumb.png" width="504" height="389" /></a> </p>
<p>This time we select which objects in our diagram that will be generated on the MySQL database. Select all tables. Then click on Next button. The next dialog box will appear:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB forward engineer step 4" border="0" alt="MWB forward engineer step 4" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep4_thumb.png" width="504" height="392" /></a>&#160;
</p>
<p>Here we can review the SQL statements to be executed to the MySQL Server. As you can see, the SQL statement was generated based on the diagram that was created before in the design. This including the database, tables, fields, index, and the relations between the tables. Then click on Next button. The next dialog box will appear:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep5.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB forward engineer step 5" border="0" alt="MWB forward engineer step 5" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep5_thumb.png" width="504" height="306" /></a> </p>
<p>Here we must choose the database connection that we have defined before. If there’s a change on the hostname, username and password, you still can do it here by modifying it on the appropriate field. Then click on Execute button to execute the SQL statement on the server. The next dialog box will appear:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="MWB forward engineer step 6" border="0" alt="MWB forward engineer step 6" src="http://www.dijexi.com/wp-content/uploads/2009/08/MWBforwardengineerstep6_thumb.png" width="504" height="306" /></a> </p>
<p>The execution is now complete. It means that the database is created on the server with the tables and relations as defined in our diagram. You may check that on any MySQL front end program like phpMyAdmin, Navicat MySQL, and any other programs. Here is the snapshot of the database structure as viewed with Navicat MySQL program:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/ThedatabaseissuccessfullycreatedinMySQLserver.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="The database is successfully created in MySQL server" border="0" alt="The database is successfully created in MySQL server" src="http://www.dijexi.com/wp-content/uploads/2009/08/ThedatabaseissuccessfullycreatedinMySQLserver_thumb.png" width="504" height="306" /></a> </p>
<p>&#160;</p>
</p>
</p>
<p>In this part, we have discussed the database design for our application. We have drawn the entity relationship diagram (ERD) using a free tool called <a href="http://dev.mysql.com/downloads/workbench/5.1.html">MySQL workbench</a>. Also we have created our database structure directly to a MySQL server that can be used by our application. You may download the diagram <a href="http://www.dijexi.com/wp-content/uploads/2009/08/erd-cashbank1.zip" target="_blank">MWB file here</a>.</p>
<p>In the next article, we are ready to begin the coding of the application.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:257932c8-f2ab-4ad1-a4e5-cc5e998998b6" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/CodeIgniter+tutorial" rel="tag">CodeIgniter tutorial</a>,<a href="http://technorati.com/tags/php+tutorial" rel="tag">php tutorial</a>,<a href="http://technorati.com/tags/accounting+system" rel="tag">accounting system</a>,<a href="http://technorati.com/tags/UML" rel="tag">UML</a>,<a href="http://technorati.com/tags/ERD" rel="tag">ERD</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 2 The Application Specification and UML Diagrams</a></li><li><a href="http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fcodeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database%2F&amp;linkname=CodeIgniter%20Tutorial%3A%20%5BCreating%20Accounting%20Application%5D%20Part%203%20ER%20Diagram%20and%20Creating%20Database"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to Debug PHP Program Remotely using phpDesigner 2008</title>
		<link>http://www.dijexi.com/2009/08/how-to-debug-php-program-remotely-using-phpdesigner-2008/</link>
		<comments>http://www.dijexi.com/2009/08/how-to-debug-php-program-remotely-using-phpdesigner-2008/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 13:11:25 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[php debug]]></category>
		<category><![CDATA[phpdesigner]]></category>
		<category><![CDATA[remote debug]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/how-to-debug-php-program-remotely-using-phpdesigner-2008/</guid>
		<description><![CDATA[Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program thus making it behave as expected. PHP has an extension that allows us to debug PHP scripts in live manner, called Xdebug. This article explains how to use and configure Xdebug within phpDesigner IDE from MPSOFTWARE. [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p><a class="zem_slink" title="Debugging" href="http://en.wikipedia.org/wiki/Debugging" rel="wikipedia">Debugging</a> is a methodical process of finding and reducing the number of bugs, or defects, in a computer program thus making it behave as expected. <a class="zem_slink" title="PHP" href="http://php.net/" rel="homepage">PHP</a> has an extension that allows us to debug PHP scripts in live manner, called Xdebug. This article explains how to use and configure Xdebug within phpDesigner <a class="zem_slink" title="Integrated development environment" href="http://en.wikipedia.org/wiki/Integrated_development_environment" rel="wikipedia">IDE</a> from <a href="http://www.mpsoftware.dk/">MPSOFTWARE</a>. Debugging with Xdebug allows the programmer to analyze, evaluate and find errors in the code line by line.</p>
<p> <span id="more-1117"></span><br />
<h2>Configuration</h2>
<p>In order to use Xdebug you must have PHP installed local on your computer configured with the Xdebug extesion. </p>
<p>By default, phpDesigner 2008 is installed with PHP and Xdebug configured otherwise please follow these steps: </p>
<ol>
<li>Download the latest PHP 5.x.x. package (not the installer) from <a href="http://www.php.net/">http://www.php.net</a> or use <a class="zem_slink" title="XAMPP" href="http://www.apachefriends.org/en/xampp.html" rel="homepage">XAMPP</a> for easier PHP, Apache, and <a class="zem_slink" title="MySQL" href="http://www.mysql.com/" rel="homepage">MySQL</a> installation </li>
<li>Download the Xdebug extension for the PHP version you have installed in the previous step from <a href="http://www.xdebug.com/">http://www.xdebug.com</a>. For example if you have PHP 5.2.1 installed, you need Xdebug 5.2.1 </li>
<li>Place the Xdebug extension in the extension folder where you installed PHP, for example c:\&#8230;\PHP\ext </li>
<li>In the folder where you installed PHP, open php.ini. there is no such file, locate php.ini-dist and rename it to php.ini. If you are using XAMPP, the file is located on c:\xampp\php\php.ini or C:\xampp\apache\bin\php.ini </li>
<li>Add the following line to php.ini in the [Zend] section:     <br /><strong>zend_extension_ts = &quot;./ext/php_xdebug.dll&quot;       <br />xdebug.remote_enable=on        <br />xdebug.profiler_enable_trigger=on</strong></li>
</ol>
<p>Configure phpDesigner 2008 to know where to find the PHP interpreter (php.exe, win-php.exe or php-cgi.exe). </p>
<ol>
<li>On the Tools menu, point to Preferences </li>
<li>Select Debugger </li>
<li>In the field &#8216;PHP&#8217; type in the path for the PHP interpreter (.exe), or click the Browse button to locate the PHP interpreter</li>
</ol>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/PHPDebugwithxdebugconfigurationinphpDesigner.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP Debug with xdebug configuration in phpDesigner" border="0" alt="PHP Debug with xdebug configuration in phpDesigner" src="http://www.dijexi.com/wp-content/uploads/2009/08/PHPDebugwithxdebugconfigurationinphpDesigner_thumb.png" width="504" height="375" /></a> </p>
<p>Optionally if you run your apache <a class="zem_slink" title="Web server" href="http://en.wikipedia.org/wiki/Web_server" rel="wikipedia">web server</a> on other port than 80, then you should set the Localhost section on the Debugger:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/PHPDebugwithxdebughostconfigurationinphpDesigner.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP Debug with xdebug host configuration in phpDesigner" border="0" alt="PHP Debug with xdebug host configuration in phpDesigner" src="http://www.dijexi.com/wp-content/uploads/2009/08/PHPDebugwithxdebughostconfigurationinphpDesigner_thumb.png" width="504" height="373" /></a> </p>
<p>Set the Server path to localhost or any hostname that you want to debug on and the Port that the server is running on. The default value is 80.</p>
<h2>Start Debugging Sessions</h2>
<p>Before you can start a debug session, the Xdebug server must be started. You can start, restart or stop the Xdebug server on the Debug menu, select Xdebug IDE server. </p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/PHPeditorstartxdebugserver.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP editor start xdebug server" border="0" alt="PHP editor start xdebug server" src="http://www.dijexi.com/wp-content/uploads/2009/08/PHPeditorstartxdebugserver_thumb.png" width="504" height="266" /></a> </p>
<p>Now you can begin debugging your script. Place a <a class="zem_slink" title="Breakpoint" href="http://en.wikipedia.org/wiki/Breakpoint" rel="wikipedia">breakpoint</a> on a script that you wish to debug. This is done by placing the cursor on the correct line on the file. Then select menu Debug – Toggle breakpoint or pressing F5 button on your keyboard. A red line will appear on the line. </p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/PHPdebugsettingbreakpointonaline.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP debug setting breakpoint on a line" border="0" alt="PHP debug setting breakpoint on a line" src="http://www.dijexi.com/wp-content/uploads/2009/08/PHPdebugsettingbreakpointonaline_thumb.png" width="504" height="321" /></a> </p>
<p>Then, start a debug session from within the IDE or from the web <a class="zem_slink" title="Web browser" href="http://en.wikipedia.org/wiki/Web_browser" rel="wikipedia">browser</a> and execute your script until the first breakpoint or error occurs. Select a main script file of your project, especially when you have a large project that consists of many files included in the main script file. This file is usually index.php. To start a debugging session, press F9 key. Your script will be suspended if there’s a line with breakpoint. From that line, you can: </p>
<ol>
<li>step to the next line by pressing F8 key </li>
<li>step inside a function if the line with breakpoint is a function call by pressing F7 </li>
<li>continue running the program by pressing F9 key</li>
</ol>
<p>When the execution is suspending, you can view the content and type of a variable by placing your <a class="zem_slink" title="Cursor (computers)" href="http://en.wikipedia.org/wiki/Cursor_%28computers%29" rel="wikipedia">mouse pointer</a> over that variable.</p>
<p> <em>
</p>
<p>   <a href="http://www.dijexi.com/wp-content/uploads/2009/08/PHPdebuggininaction.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP debuggin in action" border="0" alt="PHP debuggin in action" src="http://www.dijexi.com/wp-content/uploads/2009/08/PHPdebuggininaction_thumb.png" width="504" height="337" /></a> </em>
<p>You can also press <a class="zem_slink" title="Function key" href="http://en.wikipedia.org/wiki/Function_key" rel="wikipedia">F4 key</a> that will start the debug session as in Run but will pause the execution until the line at cursor is reached. If any breakpoints or errors occurs before the line at cursor is reached the execution might be paused.</p>
<p>You may also press Shift-F8 key that will start the debug session as in Run but will pause when pressing the return key. If any breakpoints or errors occurs before the line at cursor is reached the execution might be paused. </p>
<p>To start a debug session from the web browser, execute the script you want to debug in the web browser. phpDesigner 2008 will break at the breakpoints you have set for that script or if any errors occours. </p>
<p>To trace the course of the executions in your script throughout the debugging session, use Call Stack panel. On the View menu, click Tool Panels and select Call stack. </p>
<p>To display the value of all global and local variables throughout the debugging session, use Variable panel. On the View menu, click Tool Panels and select Variables. </p>
<p>To monitor variables, objects, properties etc. throughout the debugging session use Watches panel. Monitored variables should start with a &quot;$&quot; (dollar sign). On the View menu, click Tool Panels and select Watches. </p>
<p>To evaluate and test expressions in your script use move the cursor upon variables to see their values. You can manipulate variables directly during a debugging session. Manipulated or injected variables will affect the value of the variable when the execution of the script continues. On the View menu, click Tool Panels and select Evaluation. </p>
<p>Messages that Xdebug sends to phpDesigner debug Log panel. On the View menu, click Tool Panels and select Log. </p>
</p>
</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:958ce4d8-f4b1-418b-b31a-b901ccd65e77" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/php+debug" rel="tag">php debug</a>,<a href="http://technorati.com/tags/phpdesigner" rel="tag">phpdesigner</a>,<a href="http://technorati.com/tags/remote+debug" rel="tag">remote debug</a></div>
</p>
</p>
</p>
</p>
</p>
<div class="zemanta-related">
<h6 style="font-size: 1em" class="zemanta-related-title">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://chris.pirillo.com/tips-for-programming-and-php/">Tips for Programming and PHP</a> (chris.pirillo.com) </li>
<li class="zemanta-article-ul-li"><a href="http://www.downes.ca/cgi-bin/page.cgi?post=49564">Xampp</a> (downes.ca) </li>
<li class="zemanta-article-ul-li"><a href="http://www.killerstartups.com/Web-App-Tools/phpanywhere-net-coding-wherever-you-are">PHPAnywhere.net &#8211; Coding Wherever You Are</a> (killerstartups.com) </li>
<li class="zemanta-article-ul-li"><a href="http://www.ghacks.net/2009/03/28/home-web-server/">Run Your Own Home Web Server</a> (ghacks.net) </li>
<li class="zemanta-article-ul-li"><a href="http://www.slumpedoverkeyboarddead.com/2009/07/28/installing-apache2-with-php5-and-mysql-support-on-ubuntu-9-04-lamp/">Installing Apache2 With PHP5 And MySQL Support On Ubuntu 9.04 (LAMP)</a> (slumpedoverkeyboarddead.com) </li>
<li class="zemanta-article-ul-li"><a href="http://creativetechs.com/tipsblog/easily-test-php-or-mysql-websites-on-your-mac/">Easily test PHP or MySQL Websites on your Mac.</a> (creativetechs.com) </li>
<li class="zemanta-article-ul-li"><a href="http://ajaxian.com/archives/firephp-tying-together-firebug-and-php">FirePHP: Tying together Firebug and PHP</a> (ajaxian.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.nofluffjuststuff.com/blog/cal_evans/2009/07/xampp_php_5_3_pear_and_phar_what_a_mess_.html?utm_source=blogitem&amp;utm_medium=rss&amp;utm_campaign=blogrss">XAMPP, PHP 5.3, PEAR, and PHAR (what a mess)</a> (nofluffjuststuff.com)</li>
</ul></div>
</p>
<div style="margin-top: 10px; height: 15px" class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/a4456060-c178-4796-9ae7-e01bd462686a/"><img style="border-bottom-style: none; border-right-style: none; border-top-style: none; float: right; border-left-style: none" class="zemanta-pixie-img" alt="Reblog this post [with Zemanta]" src="http://img.zemanta.com/reblog_e.png?x-id=a4456060-c178-4796-9ae7-e01bd462686a" /></a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/06/tutorial-cara-debug-program-dan-menggunakan-help/" rel="bookmark">11. Debug dan Menggunakan Help</a></li><li><a href="http://www.dijexi.com/2010/05/setup-kannel-sms-gateway-on-ubuntu/" rel="bookmark">Setup Kannel SMS Gateway on Ubuntu</a></li><li><a href="http://www.dijexi.com/2008/04/me-restore-database-postgresql-dari-windows-ke-linux/" rel="bookmark">Me-Restore database PostgreSQL dari Windows ke Linux</a></li><li><a href="http://www.dijexi.com/2009/07/list-of-free-downloadable-wordpress-themes/" rel="bookmark">List of Free Downloadable WordPress Themes</a></li><li><a href="http://www.dijexi.com/2009/06/joomla-1-5-mengganti-judul-welcome-to-the-frontpage/" rel="bookmark">Joomla 1.5: Mengganti Judul Welcome to the Frontpage</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fhow-to-debug-php-program-remotely-using-phpdesigner-2008%2F&amp;linkname=How%20to%20Debug%20PHP%20Program%20Remotely%20using%20phpDesigner%202008"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/how-to-debug-php-program-remotely-using-phpdesigner-2008/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Tutorial: [Creating Accounting Application] Part 2 The Application Specification and UML Diagrams</title>
		<link>http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/</link>
		<comments>http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 05:15:32 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[accounting system]]></category>
		<category><![CDATA[CodeIgniter tutorial]]></category>
		<category><![CDATA[php tutorial]]></category>
		<category><![CDATA[UML]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/</guid>
		<description><![CDATA[In this part of the tutorial series we will discuss about the application specification. After defining the user requirements we will do the analysis and designing the using UML use cases and class diagram. We are going to use a free UML diagramming tool called StarUML. You can download the program here if you have [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>In this part of the tutorial series we will discuss about the application specification. After defining the user requirements we will do the analysis and designing the using <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML</a> use cases and <a href="http://en.wikipedia.org/wiki/Class_diagram">class diagram</a>. We are going to use a free UML diagramming tool called <a href="http://staruml.sourceforge.net/en/">StarUML</a>. You can <a href="http://staruml.sourceforge.net/en/download.php">download the program here</a> if you have not installed it in your computer.</p>
<p> <span id="more-1057"></span><br />
<h2>User Requirements</h2>
<p>Listed here is our web based accounting application user requirement and specification:</p>
<ul>
<li>application must be web based, accessible anywhere from the internet </li>
<li>multi-users, with data entry, supervisor, manager, and administrator user group </li>
<li>user must provide their correct user id and password to access the system </li>
<li>data-entry user group can input cashbook and bankbook transaction as well as any journal entry transaction beside the cash and bank book transaction </li>
<li>supervisor user group can manage the transaction, for example to correct, edit, and delete transaction previously entered by the data entry user </li>
<li>data entry user group can do a posting process in order that the system can generate balance sheet, profit and loss report automatically </li>
<li>data entry, supervisor and manager user group can view the daily, monthly, and yearly transaction report, as well as balance sheet, profit and loss report </li>
<li>administrator user group can manage user data (add, delete, and modify), and reset it’s password </li>
</ul>
<p>&#160;</p>
<h2>Use Case</h2>
<p>Based on the user requirement, we draw a use case diagram as follow:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/MainUseCase.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Main Use Case" border="0" alt="Main Use Case" src="http://www.dijexi.com/wp-content/uploads/2009/08/MainUseCase_thumb.jpg" width="502" height="446" /></a> </p>
<p>As you can see on the Use Case diagram here is the actor and use case matrix table:</p>
<table border="1" cellspacing="0" cellpadding="2" width="499">
<tbody>
<tr>
<td valign="top" width="99">
<p align="center"><strong>Actor              <br />Use Case</strong> </p>
</td>
<td valign="top" width="92">
<p align="center"><strong>Data Entry</strong></p>
</td>
<td valign="top" width="101">
<p align="center"><strong>Supervisor</strong></p>
</td>
<td valign="top" width="97">
<p align="center"><strong>Manager</strong></p>
</td>
<td valign="top" width="108">
<p align="center"><strong>Administrator</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="100">
<p align="center">Manage Cashbook Transaction</p>
</td>
<td valign="top" width="90">
<p align="center">-</p>
</td>
<td valign="top" width="100">
<p align="center">o</p>
</td>
<td valign="top" width="96">
<p align="center">-</p>
</td>
<td valign="top" width="111">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Manage Bankbook Transaction</p>
</td>
<td valign="top" width="89">
<p align="center">-</p>
</td>
<td valign="top" width="100">
<p align="center">o</p>
</td>
<td valign="top" width="95">
<p align="center">-</p>
</td>
<td valign="top" width="113">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Manage Journal Transaction</p>
</td>
<td valign="top" width="89">
<p align="center">-</p>
</td>
<td valign="top" width="100">
<p align="center">o</p>
</td>
<td valign="top" width="95">
<p align="center">-</p>
</td>
<td valign="top" width="114">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Manage Chart of Account</p>
</td>
<td valign="top" width="89">
<p align="center">-</p>
</td>
<td valign="top" width="99">
<p align="center">o</p>
</td>
<td valign="top" width="94">
<p align="center">-</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">View Cashbook Transaction Report</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">o</p>
</td>
<td valign="top" width="94">
<p align="center">o</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">View Bankbook Transaction Report</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">o</p>
</td>
<td valign="top" width="94">
<p align="center">o</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">View Journal Transaction Report</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">o</p>
</td>
<td valign="top" width="94">
<p align="center">o</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Enter Cashbook Transaction</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">-</p>
</td>
<td valign="top" width="94">
<p align="center">-</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Enter Bankbook Transaction</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">-</p>
</td>
<td valign="top" width="94">
<p align="center">-</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Enter Journal Transaction</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">-</p>
</td>
<td valign="top" width="94">
<p align="center">-</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Posting</p>
</td>
<td valign="top" width="88">
<p align="center">o</p>
</td>
<td valign="top" width="99">
<p align="center">-</p>
</td>
<td valign="top" width="94">
<p align="center">-</p>
</td>
<td valign="top" width="115">
<p align="center">-</p>
</td>
</tr>
<tr>
<td valign="top" width="101">
<p align="center">Manage Users</p>
</td>
<td valign="top" width="88">
<p align="center"></p>
</td>
<td valign="top" width="100">
<p align="center">-</p>
</td>
<td valign="top" width="95">
<p align="center">-</p>
</td>
<td valign="top" width="116">
<p align="center">o</p>
</td>
</tr>
</tbody>
</table>
<p>You may download the StarUML <a href="http://www.dijexi.com/wp-content/uploads/2009/08/Aplikasi-Kas-Bank.zip">diagram file here</a>.</p>
<h2>Model Class Diagram </h2>
<p>Based on the user requirement and use case diagram above, we then draw a class diagram. We split the class diagram into Model Class Diagram and Controller Class Diagram as we are going to use MVC (model-view-controller) design pattern for the application.</p>
<p>The Model Class Diagram is as follow:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/ModelDiagram.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Model Diagram" border="0" alt="Model Diagram" src="http://www.dijexi.com/wp-content/uploads/2009/08/ModelDiagram_thumb.jpg" width="520" height="360" /></a> </p>
<h3>Bankbook_model</h3>
<p>This model class represents the database access and data processing of the bankbook document data to be used by it’s controller class.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">get()</td>
<td valign="top" width="250">Get one record of Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">getAll()</td>
<td valign="top" width="250">Get all record of Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add one new record </td>
</tr>
<tr>
<td valign="top" width="250">addDetails()</td>
<td valign="top" width="250">Add one new detail record</td>
</tr>
<tr>
<td valign="top" width="250">getDetails()</td>
<td valign="top" width="250">Get all details record of a Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">sumTotal()</td>
<td valign="top" width="250">Summarize total amount based on the details record</td>
</tr>
<tr>
<td valign="top" width="250">getNewNumber()</td>
<td valign="top" width="250">Get a new document number after the last document number</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete one record of Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">posting()</td>
<td valign="top" width="250">Do the posting process to generate accounting journal entry of Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">update()</td>
<td valign="top" width="250">Update one record of Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">deleteDetails()</td>
<td valign="top" width="250">Delete detail record of a Bankbook document</td>
</tr>
<tr>
<td valign="top" width="250">updateDetails()</td>
<td valign="top" width="250">Update detail record of Bankbook document</td>
</tr>
</tbody>
</table>
<h3></h3>
<h3>Cashbook_model</h3>
<p>This model class represents the database access and data processing of the cashbook document data to be used by it’s controller class.</p>
<table border="0" cellspacing="0" cellpadding="2" width="502">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">get()</td>
<td valign="top" width="250">Get one record of Journal document</td>
</tr>
<tr>
<td valign="top" width="250">getAll()</td>
<td valign="top" width="250">Get all record of Journal document</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add one new record </td>
</tr>
<tr>
<td valign="top" width="250">addDetails()</td>
<td valign="top" width="250">Add one new detail record</td>
</tr>
<tr>
<td valign="top" width="250">getDetails()</td>
<td valign="top" width="250">Get all details record of a Journal document</td>
</tr>
<tr>
<td valign="top" width="250">sumTotal()</td>
<td valign="top" width="250">Summarize total amount based on the details record</td>
</tr>
<tr>
<td valign="top" width="250">getNewNumber()</td>
<td valign="top" width="250">Get a new document number after the last document number</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete one record of Journal document</td>
</tr>
<tr>
<td valign="top" width="250">posting()</td>
<td valign="top" width="250">Do the posting process to generate accounting journal entry of Journal document</td>
</tr>
<tr>
<td valign="top" width="250">update()</td>
<td valign="top" width="250">Update one record of Journal document</td>
</tr>
<tr>
<td valign="top" width="250">deleteDetails()</td>
<td valign="top" width="250">Delete detail record of a Journal document</td>
</tr>
<tr>
<td valign="top" width="250">updateDetails()</td>
<td valign="top" width="250">Update detail record of Journal document</td>
</tr>
</tbody>
</table>
<h3>Journal_model</h3>
<p>This model class represents the database access and data processing of the journal document data to be used by it’s controller class.</p>
<table border="0" cellspacing="0" cellpadding="2" width="502">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">get()</td>
<td valign="top" width="250">Get one record of Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">getAll()</td>
<td valign="top" width="250">Get all record of Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add one new record </td>
</tr>
<tr>
<td valign="top" width="250">addDetails()</td>
<td valign="top" width="250">Add one new detail record</td>
</tr>
<tr>
<td valign="top" width="250">getDetails()</td>
<td valign="top" width="250">Get all details record of a Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">sumTotal()</td>
<td valign="top" width="250">Summarize total amount based on the details record</td>
</tr>
<tr>
<td valign="top" width="250">getNewNumber()</td>
<td valign="top" width="250">Get a new document number after the last document number</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete one record of Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">posting()</td>
<td valign="top" width="250">Do the posting process to generate accounting journal entry of Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">update()</td>
<td valign="top" width="250">Update one record of Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">deleteDetails()</td>
<td valign="top" width="250">Delete detail record of a Cashbook document</td>
</tr>
<tr>
<td valign="top" width="250">updateDetails()</td>
<td valign="top" width="250">Update detail record of Cashbook document</td>
</tr>
</tbody>
</table>
<h3>Coa_model</h3>
<p>This model class represents the database access and data processing of the chart of account data to be used by it’s controller class.</p>
<table border="0" cellspacing="0" cellpadding="2" width="502">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add one new record </td>
</tr>
<tr>
<td valign="top" width="250">addChild()</td>
<td valign="top" width="250">Add one new child record of a COA record</td>
</tr>
<tr>
<td valign="top" width="250">get()</td>
<td valign="top" width="250">Get one record of COA record</td>
</tr>
<tr>
<td valign="top" width="250">getAll()</td>
<td valign="top" width="250">Get all record </td>
</tr>
<tr>
<td valign="top" width="250">findByNameOrCode()</td>
<td valign="top" width="250">Find COAs based on keyword of code or name</td>
</tr>
<tr>
<td valign="top" width="250">getByCode()</td>
<td valign="top" width="250">Find COA based on it’s code</td>
</tr>
<tr>
<td valign="top" width="250">getTrialBalance()</td>
<td valign="top" width="250">Returns records of trial balance report</td>
</tr>
<tr>
<td valign="top" width="250">getBalanceSheet()</td>
<td valign="top" width="250">Returns records of balance sheet</td>
</tr>
<tr>
<td valign="top" width="250">getProfilLoss()</td>
<td valign="top" width="250">Returns records of profit and loss statement</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete one record of COA</td>
</tr>
<tr>
<td valign="top" width="250">update()</td>
<td valign="top" width="250">Update one record of COA</td>
</tr>
</tbody>
</table>
<h2>Controller Class Diagram</h2>
<p>And here is the Controller Class Diagram:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/08/ControllerDiagram.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Controller Diagram" border="0" alt="Controller Diagram" src="http://www.dijexi.com/wp-content/uploads/2009/08/ControllerDiagram_thumb.jpg" width="520" height="305" /></a> </p>
<h3>Bankbook</h3>
<p>This class represents the controller of bankbook document. It’s the class that users will access directly through browser user interface.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">Bankbook()</td>
<td valign="top" width="250">The class constructor where the class initialization will be put</td>
</tr>
<tr>
<td valign="top" width="250">index()</td>
<td valign="top" width="250">The index page of the controller class</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add new bankbook record interface, will call addNew() method on it’s model class </td>
</tr>
<tr>
<td valign="top" width="250">editForm()</td>
<td valign="top" width="250">Show an edit form for user to edit the data</td>
</tr>
<tr>
<td valign="top" width="250">save()</td>
<td valign="top" width="250">Save data from the edit form, will call update() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete data, will call delete() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">viewReport()</td>
<td valign="top" width="250">Show the list of currently available bankbook documents</td>
</tr>
<tr>
<td valign="top" width="250">addDetail()</td>
<td valign="top" width="250">Add new detail record to the currently edited bankbook document, will call addDetails() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
<td valign="top" width="250">&#160;</td>
</tr>
</tbody>
</table>
<p>&#160;</p>
<h3>Cashbook</h3>
<p>This class represents the controller of cashbook document. It’s the class that users will access directly through browser user interface.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">Cashbook()</td>
<td valign="top" width="250">The class constructor where the class initialization will be put</td>
</tr>
<tr>
<td valign="top" width="250">index()</td>
<td valign="top" width="250">The index page of the controller class</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add new cashbook record interface, will call addNew() method on it’s model class </td>
</tr>
<tr>
<td valign="top" width="250">editForm()</td>
<td valign="top" width="250">Show an edit form for user to edit the data</td>
</tr>
<tr>
<td valign="top" width="250">save()</td>
<td valign="top" width="250">Save data from the edit form, will call update() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete data, will call delete() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">viewReport()</td>
<td valign="top" width="250">Show the list of currently available cashbook documents</td>
</tr>
<tr>
<td valign="top" width="250">addDetail()</td>
<td valign="top" width="250">Add new detail record to the currently edited cashbook document, will call addDetails() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
</tr>
</tbody>
</table>
<h3>Journal</h3>
<p>This class represents the controller of journal document. It’s the class that users will access directly through browser user interface.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">Journal()</td>
<td valign="top" width="250">The class constructor where the class initialization will be put</td>
</tr>
<tr>
<td valign="top" width="250">index()</td>
<td valign="top" width="250">The index page of the controller class</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add new journal record interface, will call addNew() method on it’s model class </td>
</tr>
<tr>
<td valign="top" width="250">editForm()</td>
<td valign="top" width="250">Show an edit form for user to edit the data</td>
</tr>
<tr>
<td valign="top" width="250">save()</td>
<td valign="top" width="250">Save data from the edit form, will call update() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete data, will call delete() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">viewReport()</td>
<td valign="top" width="250">Show the list of currently available journal documents</td>
</tr>
<tr>
<td valign="top" width="250">addDetail()</td>
<td valign="top" width="250">Add new detail record to the currently edited journal document, will call addDetails() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
</tr>
</tbody>
</table>
<h3>Coa</h3>
<p>This class represents the controller of bankbook document. It’s the class that users will access directly through browser user interface.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">Coa()</td>
<td valign="top" width="250">The class constructor where the class initialization will be put</td>
</tr>
<tr>
<td valign="top" width="250">index()</td>
<td valign="top" width="250">The index page of the controller class</td>
</tr>
<tr>
<td valign="top" width="250">addNew()</td>
<td valign="top" width="250">Add new COA record interface, will call addNew() method on it’s model class </td>
</tr>
<tr>
<td valign="top" width="250">editForm()</td>
<td valign="top" width="250">Show an edit form for user to edit the data</td>
</tr>
<tr>
<td valign="top" width="250">save()</td>
<td valign="top" width="250">Save data from the edit form, will call update() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">delete()</td>
<td valign="top" width="250">Delete data, will call delete() method on it’s model class</td>
</tr>
<tr>
<td valign="top" width="250">listCoa()</td>
<td valign="top" width="250">Show the list of currently available COA</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
</tr>
</tbody>
</table>
<h3>Mainpage</h3>
<p>This class represents the controller of bankbook document. It’s the class that users will access directly through browser user interface.</p>
<table border="0" cellspacing="0" cellpadding="2" width="500">
<tbody>
<tr>
<td valign="top" width="250">
<p align="center"><strong>Method</strong></p>
</td>
<td valign="top" width="250">
<p align="center"><strong>Description</strong></p>
</td>
</tr>
<tr>
<td valign="top" width="250">Mainpage()</td>
<td valign="top" width="250">The class constructor where the class initialization will be put</td>
</tr>
<tr>
<td valign="top" width="250">index()</td>
<td valign="top" width="250">The index page of the controller class</td>
</tr>
<tr>
<td valign="top" width="250">doPosting()</td>
<td valign="top" width="250">Do the posting process for bankbook, cashbook, and journal</td>
</tr>
<tr>
<td valign="top" width="250">balanceSheet()</td>
<td valign="top" width="250">Show balance sheet report, calling the getBalanceSheet() method from Coa_model class</td>
</tr>
<tr>
<td valign="top" width="250">profitLoss()</td>
<td valign="top" width="250">Show profit and loss report, calling the getProfitLoss() method from Coa_model class</td>
</tr>
<tr>
<td valign="top" width="250">trialBalance()</td>
<td valign="top" width="250">Show trial balance report, calling the getTrialBalance() method from Coa_model class</td>
</tr>
<tr>
<td valign="top" width="250">&#160;</td>
</tr>
</tbody>
</table>
<p>You may download the StarUML <a href="http://www.dijexi.com/wp-content/uploads/2009/08/Aplikasi-Kas-Bank.zip">diagram file here</a>.</p>
<p>In the next part of the article we are going to discuss the Entity Relationship Diagram (ERD) to design the database structure that will hold the data for our application.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9b37e77d-2c09-42de-8862-43ce02ad6787" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/CodeIgniter+tutorial" rel="tag">CodeIgniter tutorial</a>,<a href="http://technorati.com/tags/php+tutorial" rel="tag">php tutorial</a>,<a href="http://technorati.com/tags/accounting+system" rel="tag">accounting system</a>,<a href="http://technorati.com/tags/UML" rel="tag">UML</a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li><li><a href="http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 3 ER Diagram and Creating Database</a></li><li><a href="http://www.dijexi.com/2009/08/how-to-mix-segment-and-query-string-in-codeigniter/" rel="bookmark">How to Mix Segment and Query String in CodeIgniter</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F08%2Fcodeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams%2F&amp;linkname=CodeIgniter%20Tutorial%3A%20%5BCreating%20Accounting%20Application%5D%20Part%202%20The%20Application%20Specification%20and%20UML%20Diagrams"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</title>
		<link>http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/</link>
		<comments>http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 07:06:06 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[accounting system]]></category>
		<category><![CDATA[CodeIgniter tutorial]]></category>
		<category><![CDATA[php tutorial]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/</guid>
		<description><![CDATA[This tutorial series explain how to develop a web based application using CodeIgniter, the PHP application framework. As you might already know, CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. In this tutorial, we took the [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>This tutorial series explain how to develop a web based application using <a class="zem_slink" title="CodeIgniter" rel="homepage" href="http://www.codeigniter.com/">CodeIgniter</a>, the <a class="zem_slink" title="PHP" rel="homepage" href="http://php.net/">PHP</a> <a class="zem_slink" title="Application framework" rel="wikipedia" href="http://en.wikipedia.org/wiki/Application_framework">application framework</a>. As you might already know, CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications.</p>
<p>In this tutorial, we took the case of developing a basic web based accounting application that can input cash book and bank book data transaction and journal entry.</p>
<p>The tutorial series will cover:</p>
<ul>
<li>Part 1 Setting Up the Environment: <a class="zem_slink" title="XAMPP" rel="homepage" href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> (apache, mysql, and PHP) and CodeIgniter</li>
<li>Part 2 The application specification, analysis and design using <a class="zem_slink" title="Unified Modeling Language" rel="wikipedia" href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML</a> use case and <a class="zem_slink" title="Class diagram" rel="wikipedia" href="http://en.wikipedia.org/wiki/Class_diagram">class diagram</a> using free UML diagram tool <a class="zem_slink" title="StarUML" rel="homepage" href="http://staruml.sourceforge.net/en/">StarUML</a>.. (<a href="http://staruml.sourceforge.net/en/download.php" target="_blank">download here</a> if you have not install it in your computer) . We also need to install StarUML <a href="http://staruml.sourceforge.net/en/templates.php" target="_blank">PHP 5 Code Generator Template</a> to automatically generate the class files from class diagram created</li>
<li>Part 3 ER Diagram and Creating Database using <a href="http://dev.mysql.com/downloads/workbench/5.1.html" target="_blank">MySQL workbench</a>, formerly <a href="http://www.fabforce.net/dbdesigner4/downloads.php" target="_blank">fabForce ERD tools</a> for MySQL</li>
<li>Part 4, preparing to code in CodeIgniter, exporting class diagram to PHP scripts</li>
<li>Part 5 Coding, the Mainpage</li>
<li>Part 6 Coding, the and COA Module explain the application coding using CodeIgniter</li>
<li>Part 8 Coding, the Cashbook Module explain the application coding using CodeIgniter</li>
<li>Part 7 Coding, the Bankbook Module explain the application coding using CodeIgniter</li>
<li>Part 8 Coding, the Journal Module explain the application coding using CodeIgniter</li>
<li>Part 9 Coding, the Reporting Module explain the application coding using CodeIgniter</li>
<li>Part 10 Conslusion and Further Development: AJAX, Facebook Application</li>
</ul>
<p><span id="more-1041"></span></p>
<h2><a href="http://www.dijexi.com/wp-content/uploads/2009/07/11.png"><img style="margin: 0px 15px 10px 0px; display: inline; border-width: 0px;" title="1" src="http://www.dijexi.com/wp-content/uploads/2009/07/1_thumb1.png" border="0" alt="1" width="84" height="108" align="left" /></a> Part 1 Setting Up The Environment</h2>
<h3>Installing XAMPP</h3>
<p><a href="http://www.apachefriends.org/en/xampp.html" target="_blank">Click here for detailed instruction</a> on how to install XAMPP. Make sure that you can access the web server installed in XAMPP by entering the URL <a href="http://localhost/">http://localhost</a>. If you did, a page will appear showing that the XAMPP was installed successfully. Try clicking on the phpinfo() link to make sure that PHP installation was also successful. Try also the CD Collection Demos to make sure that MySQL installed correctly. If something was not right, go back to the installation article and make sure that the server configuration was correct.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/XAMPPSuccessfullyinstalled.png"><img style="display: inline; border-width: 0px;" title="XAMPP Successfully installed" src="http://www.dijexi.com/wp-content/uploads/2009/07/XAMPPSuccessfullyinstalled_thumb.png" border="0" alt="XAMPP Successfully installed" width="504" height="427" /></a></p>
<h3>Installing CodeIgniter</h3>
<p>Installing CodeIgniter Framework is simply easy. After you downloaded the <a href="http://codeigniter.com/download.php" target="_blank">last version package from CodeIgniter website</a>, extract the package file to your XAMPP document root, defaulted in <strong>c:\xampp\htdocs</strong>. It’s better that you rename the folder <strong>CodeIgniter_1.7.1</strong> to reflect our application name, for example: <strong>acct</strong>.</p>
<p>After extracting the file and renaming the folder to <strong>acct</strong>, your folder structure will look like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/CodeIgniterframeworkcopiedintoDocumentRoot.png"><img style="display: inline; border-width: 0px;" title="CodeIgniter framework copied into DocumentRoot" src="http://www.dijexi.com/wp-content/uploads/2009/07/CodeIgniterframeworkcopiedintoDocumentRoot_thumb.png" border="0" alt="CodeIgniter framework copied into DocumentRoot" width="504" height="389" /></a></p>
<p>You could test the CodeIgniter framework now to make sure that it’s already up. Enter the URL <a href="http://localhost/acct">http://localhost/acct</a> at your browser, then you should see something like this:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/CodeIgniterframeworksuccessfullyinstalledonXAMPP.png"><img style="display: inline; border-width: 0px;" title="CodeIgniter framework successfully installed on XAMPP" src="http://www.dijexi.com/wp-content/uploads/2009/07/CodeIgniterframeworksuccessfullyinstalledonXAMPP_thumb.png" border="0" alt="CodeIgniter framework successfully installed on XAMPP" width="504" height="427" /></a></p>
<p>Congratulation! You have done the first step of creating our web based Accounting Application. You could now continue to the next step about the application specification we are going to develop, and the design and analysis using UML diagram.</p>
<p>But, before continuing to the next step, I suggest you to check out the CodeIgniter User Manual which is already located on your server at <strong>http://&lt;yourserver&gt;/acct/user_guide</strong>.</p>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:07a4d707-a5a5-46b6-93e2-523885331dfa" class="wlWriterEditableSmartContent" style="margin: 0px; display: inline; float: none; padding: 0px;">Technorati Tags: <a rel="tag" href="http://technorati.com/tags/CodeIgniter+tutorial">CodeIgniter tutorial</a>,<a rel="tag" href="http://technorati.com/tags/php+tutorial">php tutorial</a>,<a rel="tag" href="http://technorati.com/tags/accounting+system">accounting system</a></div>
<div class="zemanta-related">
<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.killerstartups.com/Web-App-Tools/yuml-me-unified-modeling-language">Yuml.me &#8211; Unified Modeling Language </a>(killerstartups.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.downes.ca/cgi-bin/page.cgi?post=49564">Xampp </a>(downes.ca)</li>
<li class="zemanta-article-ul-li"><a href="http://www.christophermonnat.com/2009/05/building-applications-using-codeigniter-part-3-helpers/">Building Applications using CodeIgniter (Part 3) &#8211; Helpers </a>(christophermonnat.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.christophermonnat.com/2009/05/building-applications-using-codeigniter-part-2-configuration/">Building Applications using CodeIgniter (Part 2) &#8211; Configuration </a>(christophermonnat.com)</li>
</ul>
</div>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/9a50f3fe-8f2b-416b-8f7f-a715eb1e6a14/"><img class="zemanta-pixie-img" style="float: right; border-style: none;" src="http://img.zemanta.com/reblog_e.png?x-id=9a50f3fe-8f2b-416b-8f7f-a715eb1e6a14" alt="Reblog this post [with Zemanta]" /></a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li><li><a href="http://www.dijexi.com/2009/09/codeigniter-tutorial-creating-accounting-application-part-4-preparing-to-code/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 4 Preparing to Code</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-3-er-diagram-and-creating-database/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 3 ER Diagram and Creating Database</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-tutorial-creating-accounting-application-part-2-the-application-specification-and-uml-diagrams/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 2 The Application Specification and UML Diagrams</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Fcodeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment%2F&amp;linkname=CodeIgniter%20Tutorial%3A%20%5BCreating%20Accounting%20Application%5D%20Part%201%20Setting%20Up%20the%20Environment"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>PHP Library to Connect to LDAP Server</title>
		<link>http://www.dijexi.com/2009/07/php-library-to-connect-to-ldap-server/</link>
		<comments>http://www.dijexi.com/2009/07/php-library-to-connect-to-ldap-server/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 13:37:00 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[LDAP]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[ldap user manipulation]]></category>
		<category><![CDATA[php ldap connection]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/php-library-to-connect-to-ldap-server/</guid>
		<description><![CDATA[This article describes a simple PHP library to connect to an LDAP server to manipulate user data inside. The user manipulation includes adding, updating, changing password, and deleting user account. To use the library, simply include it to a script that do the manipulation. Initialization Here is the initialization section for connecting to an LDAP [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>This article describes a simple PHP library to connect to an LDAP server to manipulate user data inside. The user manipulation includes adding, updating, changing password, and deleting user account. To use the library, simply include it to a script that do the manipulation.</p>
<p> <span id="more-1031"></span><br />
<h2>Initialization</h2>
<p>Here is the initialization section for connecting to an LDAP server.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a4cfacdb-845e-4b9f-8922-0922923be2e3" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_host&#8217;</span><span class="br0">&#93;</span>&nbsp; &nbsp;&nbsp; &nbsp; = <span class="st0">&#8217;192.168.1.1&#8242;</span>;<br />
<span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_baseDN&#8217;</span><span class="br0">&#93;</span>&nbsp;&nbsp; &nbsp; = <span class="st0">&#8216;cn=people,dc=company,dc=com&#8217;</span>;<br />
<span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_manager_user&#8217;</span><span class="br0">&#93;</span>&nbsp; &nbsp;= <span class="st0">&#8216;cn=root,dc=company,dc=com&#8217;</span>;<br />
<span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_manager_pwd&#8217;</span><span class="br0">&#93;</span>&nbsp; &nbsp; = <span class="st0">&#8217;12345&#8242;</span>;<br />
&nbsp;</div>
</div>
<p>The ldap_host is the host name or IP address of the LDAP server we wish to connect to. The ldap_baseDN is the base distinguished name where our query to the server is on. The ldap_manager_user and ldap_manager_pwd is the administrative username and password that have access to manipulate other user account. Replace the above parameters to match to your own LDAP server configuration.</p>
<h2>Adding A New User Account</h2>
<p>Here is the function to add a new user account:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:d6b85e44-945a-432a-a83a-2bef2d089369" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> addUser<span class="br0">&#40;</span><span class="re0">$login</span>, <span class="re0">$pass</span>, <span class="re0">$profil</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$cfg</span>;<br />
&nbsp; &nbsp; <span class="re0">$ldapconn</span>=ldap_connect<span class="br0">&#40;</span><span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_host&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Could not connect to $ldaphost&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$username</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_manager_user&#8217;</span><span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$password</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_manager_pwd&#8217;</span><span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>@ldap_bind<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="re0">$username</span>, <span class="re0">$password</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$sr</span>=ldap_search<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_baseDN&#8217;</span><span class="br0">&#93;</span>, <span class="st0">&quot;sn=*&quot;</span><span class="br0">&#41;</span>; &nbsp; &nbsp;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;cn&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;$login&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;sn&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;$login&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;uid&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;$login&quot;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$pwd_md5</span>=<a href="http://www.php.net/base64_encode"><span class="kw3">base64_encode</span></a><span class="br0">&#40;</span><a href="http://www.php.net/pack"><span class="kw3">pack</span></a><span class="br0">&#40;</span><span class="st0">&quot;H*&quot;</span>, <a href="http://www.php.net/md5"><span class="kw3">md5</span></a><span class="br0">&#40;</span><span class="re0">$pass</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;userpassword&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;{MD5}&quot;</span>.<span class="re0">$pwd_md5</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;objectclass&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;inetOrgPerson&quot;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// add data to directory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>@ldap_add<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="st0">&quot;cn=$login, &quot;</span>. <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_baseDN&#8217;</span><span class="br0">&#93;</span> , <span class="re0">$info</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;OK&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ldap_close<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="co1">//end if ldap_bind</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="co1">//end if ldapconn</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$s</span>;<br />
<span class="br0">&#125;</span><br />
&nbsp;</div>
</div>
<p>First we do the connection to LDAP server by using ldap_connect() function. Nothing special with this function, it just take one parameter which is the address of the LDAP server to connect to. If the connection was failed simply exit the script.</p>
<p>If it was successful, the do the LDAP binding by calling ldap_bind() function. This function takes three parameters: the connection handle to server previously established, the username and password to do the binding. If it was failed, then return an error message from the server.</p>
<p>If it was successful, first do a search on the base distinguished name, prepare the user account info to be added in $info array variable, prepare the password for the account, then call the ldap_add() function. This function takes three parameter: the connection handle to the server, the user account name to be added&#160; (in the case “cn=$login, “ concatenated with the base DN), and the user account profile $info.</p>
<p>Preparing the password should be done by calling base64_encode(pack(&quot;H*&quot;, md5($pass))); if it is not, for example just using the md5(), then the password will not match.</p>
<p>If the addition was successful, the return “OK”, else return the error message from the server. Then, close the server connection by calling ldap_close() on the connection handle.</p>
<h2>Updating User Account</h2>
<p>Here is the function to update user profile:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:67c0adb6-cc75-4b7f-b4d6-21de22ced9b2" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> editUser<span class="br0">&#40;</span><span class="re0">$login</span>,<span class="re0">$profil</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$cfg</span>;<br />
&nbsp; &nbsp; <span class="re0">$ldapconn</span>=ldap_connect<span class="br0">&#40;</span><span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_host&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Could not connect to $ldaphost&quot;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span class="co1">// bila connect</span><br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// bind </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$username</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span>ldap_manager_user<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$password</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span>ldap_manager_pwd<span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>@ldap_bind<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="re0">$username</span>, <span class="re0">$password</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span>&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// prepare data</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re0">$profil</span> <span class="kw1">as</span> <span class="re0">$key</span> =&gt; <span class="re0">$value</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re0">$value</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="re0">$key</span><span class="br0">&#93;</span> = <span class="re0">$profil</span><span class="br0">&#91;</span><span class="re0">$key</span><span class="br0">&#93;</span>;&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="re0">$key</span><span class="br0">&#93;</span> = <span class="st0">&quot;n/a&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;sn&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;$login&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;uid&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;$login&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;objectclass&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;inetOrgPerson&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// add data to directory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>@ldap_modify<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="st0">&quot;cn=$login, &quot;</span>. <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_baseDN&#8217;</span><span class="br0">&#93;</span>, <span class="re0">$info</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span>=<span class="st0">&quot;OK&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ldap_close<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="co1">///end if ldapconn&nbsp; &nbsp; </span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$s</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>First we do the connection to LDAP server by using ldap_connect() function. Nothing special with this function, it just take one parameter which is the address of the LDAP server to connect to. If the connection was failed simply exit the script.</p>
<p>If it was successful, the do the LDAP binding by calling ldap_bind() function. This function takes three parameters: the connection handle to server previously established, the username and password to do the binding. If it was failed, then return an error message from the server.</p>
<p>If the binding was successful, then we iterate for each items in the $profil array, while storing the keys and values of the array into $key and $value variable for each iteration. In the $value is not empty then fill the value of the profil array of this key into $info array variable with the same key. If it was empty the fill the $info on the key with “n/a”.</p>
<p>Next, we fill the $info on the key of “sn” and “uid” with the value of $login, and the key of “objectClass” with “inetOrgPerson”.</p>
<p>Then, we call the ldap_modify() function. This function takes three parameters: the connection handle to the server, the user account name to be modified (in the case “cn=$login, “ concatenated with the base DN), and the user account profile $info.</p>
<p>If the modification was successful, the return “OK”, else return the error message from the server. Then, close the server connection by calling ldap_close() on the connection handle.</p>
<h2>Change User’s Password</h2>
<p>Here is the function to change user’s password:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4336d9a2-8172-4bcb-9d7a-1a8f5dcb0fbb" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> pwdUser<span class="br0">&#40;</span><span class="re0">$login</span>, <span class="re0">$pass</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$cfg</span>;</p>
<p>&nbsp; &nbsp; <span class="re0">$ldapconn</span>=ldap_connect<span class="br0">&#40;</span><span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_host&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Could not connect to $ldaphost&quot;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; <span class="br0">&#123;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$username</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span>ldap_manager_user<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$password</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span>ldap_manager_pwd<span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>@ldap_bind<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="re0">$username</span>, <span class="re0">$password</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$pwd_md5</span>=<a href="http://www.php.net/base64_encode"><span class="kw3">base64_encode</span></a><span class="br0">&#40;</span><a href="http://www.php.net/pack"><span class="kw3">pack</span></a><span class="br0">&#40;</span><span class="st0">&quot;H*&quot;</span>, <a href="http://www.php.net/md5"><span class="kw3">md5</span></a><span class="br0">&#40;</span><span class="re0">$pass</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$info</span><span class="br0">&#91;</span><span class="st0">&quot;userpassword&quot;</span><span class="br0">&#93;</span> = <span class="st0">&quot;{MD5}&quot;</span>.<span class="re0">$pwd_md5</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// add data to directory</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>@ldap_modify<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="st0">&quot;cn=$login, &quot;</span> . <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_baseDN&#8217;</span><span class="br0">&#93;</span>, <span class="re0">$info</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span>=<span class="st0">&quot;OK&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ldap_close<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="co1">///end if ldapconn</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$s</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>First we do the connection to LDAP server by using ldap_connect() function. Nothing special with this function, it just take one parameter which is the address of the LDAP server to connect to. If the connection was failed simply exit the script.</p>
<p>If it was successful, the do the LDAP binding by calling ldap_bind() function. This function takes three parameters: the connection handle to server previously established, the username and password to do the binding. If it was failed, then return an error message from the server.</p>
<p>If the binding was successful, we prepare the user password which should be done by calling $pwd_md5 = base64_encode(pack(&quot;H*&quot;, md5($pass))); if it is not, for example just using the md5(), then the password will not match. Then we fill the $info array on the key of “userpassword” with the value of &quot;{MD5}&quot;.$pwd_md5.</p>
<p>Then, we call the ldap_modify() function. This function takes three parameters: the connection handle to the server, the user account name to be modified (in the case “cn=$login, “ concatenated with the base DN), and the user account profile $info.</p>
<p>If the modification was successful, the return “OK”, else return the error message from the server. Then, close the server connection by calling ldap_close() on the connection handle.</p>
<h2>Delete A User Account</h2>
<p>Here is the function to delete an account:</p>
<p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:f816fb65-d0c5-45f7-a6f9-c84ae7fdf9ad" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> deleteUser<span class="br0">&#40;</span><span class="re0">$login</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/global"><span class="kw3">global</span></a> <span class="re0">$cfg</span>;</p>
<p>&nbsp; &nbsp; <span class="re0">$ldapconn</span>=ldap_connect<span class="br0">&#40;</span><span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_host&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> or <a href="http://www.php.net/die"><span class="kw3">die</span></a><span class="br0">&#40;</span><span class="st0">&quot;Could not connect to $ldaphost&quot;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; <span class="br0">&#123;</span>&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$username</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span>ldap_manager_user<span class="br0">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$password</span> = <span class="re0">$cfg</span><span class="br0">&#91;</span>ldap_manager_pwd<span class="br0">&#93;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>@ldap_bind<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="re0">$username</span>, <span class="re0">$password</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>@ldap_delete<span class="br0">&#40;</span><span class="re0">$ldapconn</span>, <span class="st0">&quot;cn=$login, &quot;</span> . <span class="re0">$cfg</span><span class="br0">&#91;</span><span class="st0">&#8216;ldap_baseDN&#8217;</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span>=<span class="st0">&quot;OK&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ldap_close<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span> <span class="co1">///end if ldapconn</span><br />
&nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">$s</span> = <span class="st0">&quot;Error: &quot;</span> . ldap_error<span class="br0">&#40;</span><span class="re0">$ldapconn</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="re0">$s</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>First we do the connection to LDAP server by using ldap_connect() function. Nothing special with this function, it just take one parameter which is the address of the LDAP server to connect to. If the connection was failed simply exit the script.</p>
<p>If it was successful, the do the LDAP binding by calling ldap_bind() function. This function takes three parameters: the connection handle to server previously established, the username and password to do the binding. If it was failed, then return an error message from the server.</p>
<p>If the binding was successful, we call the ldap_delete() function.This function takes two parameters: the connection handle to the server and the user account name to be deleted (in the case “cn=$login, “ concatenated with the base DN).</p>
<p>If the deletion was successful, the return “OK”, else return the error message from the server. Then, close the server connection by calling ldap_close() on the connection handle.</p>
<p><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:e567a9a5-9c82-430c-880e-bd073209dd56" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/php" rel="tag">php</a>,<a href="http://technorati.com/tags/ldap+connection" rel="tag">ldap connection</a>,<a href="http://technorati.com/tags/ldap+user+manipulation" rel="tag">ldap user manipulation</a></div>
</p>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://www.vitraining.com" target="_blank">vITraining.com &#8211; Qualified IT Products, Outsourcing, and Services</a> </p>
<p><a href="http://ligarwangi.com" target="_blank">Ligarwangi.com &#8211; Linux, E-book, Coffee, Gift, etc</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/mengakses-active-directory-dari-delphi/" rel="bookmark">Mengakses Active Directory dari Delphi</a></li><li><a href="http://www.dijexi.com/2010/07/how-to-send-email-on-java-application-using-javamail-api/" rel="bookmark">How to Send Email on Java Application using JavaMail API</a></li><li><a href="http://www.dijexi.com/2009/06/perl-konek-ke-postgresql/" rel="bookmark">Perl connection to PostgreSQL</a></li><li><a href="http://www.dijexi.com/2009/06/mysql-backup-with-phpmybackuppro/" rel="bookmark">MySQL Backup with phpMyBackupPro</a></li><li><a href="http://www.dijexi.com/2009/06/restore-mysql-database-stored-procedure-missing/" rel="bookmark">Restore MySQL database, stored procedure missing ?</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Fphp-library-to-connect-to-ldap-server%2F&amp;linkname=PHP%20Library%20to%20Connect%20to%20LDAP%20Server"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/php-library-to-connect-to-ldap-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Finding Element in an Array of Arrays</title>
		<link>http://www.dijexi.com/2009/07/finding-element-in-an-array-of-arrays/</link>
		<comments>http://www.dijexi.com/2009/07/finding-element-in-an-array-of-arrays/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 10:48:00 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/finding-element-in-an-array-of-arrays/</guid>
		<description><![CDATA[The listed PHP function can be used to find an element of an array that are a member of other array. For example we have a data structure like this: $data = array&#40; &#160; &#160; array&#40; &#160; &#160; &#160; &#160; &#34;user_id&#34; =&#62; &#34;akhdaniel&#34;, &#160; &#160; &#160; &#160; &#34;group_id&#34; =&#62; 1 &#160; &#160; &#41;, &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>The listed PHP function can be used to find an element of an array that are a member of other array. For example we have a data structure like this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:c4dba44a-9d75-4338-8d83-ce51906f14b7" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="re0">$data</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;akhdaniel&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;amir&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;abyan&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;ujang&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span><br />
<span class="br0">&#41;</span>;</div>
</div>
<p><span id="more-968"></span></p>
<p>Then we would like to find whether a user_id is found on inside the $data variable which is an array of arrays. To perform that operation we can use the following function:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:6de938e4-4937-45b9-88d4-e91cf438ffbd" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">function</span> in_array_of_arrays<span class="br0">&#40;</span><span class="re0">$needle</span>, <span class="re0">$haystack</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$haystack</span> <span class="kw1">as</span> <span class="re0">$id</span>=&gt;<span class="re0">$a</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span><span class="re0">$needle</span>,<span class="re0">$a</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;$needle found in id $id&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Here is how we use the function for example:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:4ce164e5-9d03-42be-ae1c-5475911b4775" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> in_array_of_arrays<span class="br0">&#40;</span><span class="st0">&quot;ujang&quot;</span>, <span class="re0">$data</span><span class="br0">&#41;</span>;</div>
</div>
<p>And here is a complete source code for testing the function:</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:453f704d-19c7-43c8-9096-3391a0e5417f" class="wlWriterEditableSmartContent">
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">&lt;?</span><br />
<span class="re0">$data</span> = <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;akhdaniel&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;amir&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;abyan&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; <a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;user_id&quot;</span> =&gt; <span class="st0">&quot;ujang&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="st0">&quot;group_id&quot;</span> =&gt; <span class="nu0">1</span><br />
&nbsp; &nbsp; <span class="br0">&#41;</span><br />
<span class="br0">&#41;</span>;</p>
<p><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;&lt;pre&gt;&quot;</span>;</p>
<p><a href="http://www.php.net/echo"><span class="kw3">echo</span></a> in_array_of_arrays<span class="br0">&#40;</span><span class="st0">&quot;ujang&quot;</span>, <span class="re0">$data</span><span class="br0">&#41;</span>;</p>
<p>
<span class="kw2">function</span> in_array_of_arrays<span class="br0">&#40;</span><span class="re0">$needle</span>, <span class="re0">$haystack</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re0">$haystack</span> <span class="kw1">as</span> <span class="re0">$id</span>=&gt;<span class="re0">$a</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><a href="http://www.php.net/in_array"><span class="kw3">in_array</span></a><span class="br0">&#40;</span><span class="re0">$needle</span>,<span class="re0">$a</span><span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;$needle found in id $id&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="kw2">?&gt;</span></div>
</div>
<p>&#160;</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:be857e88-2779-4521-9f02-71cf3a1630ac" class="wlWriterEditableSmartContent">Technorati Tags: <a href="http://technorati.com/tags/php" rel="tag">php</a>,<a href="http://technorati.com/tags/array" rel="tag">array</a></div>
</p>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://www.vitraining.com" target="_blank">vITraining.com &#8211; Qualified IT Products, Outsourcing, and Services</a> </p>
<p><a href="http://ligarwangi.com" target="_blank">Ligarwangi.com &#8211; Linux, E-book, Coffee, Gift, etc</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/gps-tracking-monitoring-application-with-google-map/" rel="bookmark">GPS Tracking Monitoring Application with Google Map</a></li><li><a href="http://www.dijexi.com/2009/07/developing-web-application-with-google-map-api/" rel="bookmark">Developing Web Application with Google Map API</a></li><li><a href="http://www.dijexi.com/2009/08/codeigniter-library-to-create-google-maps-encoded-polylines/" rel="bookmark">CodeIgniter Library to Create Google Maps Encoded Polylines</a></li><li><a href="http://www.dijexi.com/2009/10/the-secret-formula-for-1st-page-search-ranking/" rel="bookmark">The Secret Formula for 1st Page Search Ranking</a></li><li><a href="http://www.dijexi.com/2009/07/php-library-to-connect-to-ldap-server/" rel="bookmark">PHP Library to Connect to LDAP Server</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Ffinding-element-in-an-array-of-arrays%2F&amp;linkname=Finding%20Element%20in%20an%20Array%20of%20Arrays"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/finding-element-in-an-array-of-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Backup to Email</title>
		<link>http://www.dijexi.com/2009/07/mysql-backup-to-email/</link>
		<comments>http://www.dijexi.com/2009/07/mysql-backup-to-email/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 08:52:55 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[mdaemon]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/mysql-backup-to-email/</guid>
		<description><![CDATA[Image via CrunchBase This simple PHP script can be used to backup MySQL databases and then send the zipped backup file to email addresses. The backup file can then be restored by any MySQL front end program like the mysql command line, Navicat MySQL, or phpMyAdmin. The logic of the script is really simple: initialization [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><div style="margin: 1em; width: 210px; display: block; float: right" class="zemanta-img"><img style="border-bottom: medium none; border-left: medium none; display: block; border-top: medium none; border-right: medium none" alt="Image representing MySQL as depicted in CrunchBase" src="http://www.crunchbase.com/assets/images/resized/0000/1681/1681v1-max-450x450.png" width="162" height="84" />
<p style="font-size: 0.8em" class="zemanta-img-attribution">Image via <a href="http://www.crunchbase.com/">CrunchBase</a></p>
</p></div>
<p>This simple <a class="zem_slink" title="PHP" href="http://php.net/" rel="homepage">PHP</a> script can be used to backup <a class="zem_slink" title="MySQL" href="http://www.mysql.com/" rel="homepage">MySQL</a> databases and then send the zipped backup file to email addresses. The backup file can then be restored by any MySQL front end program like the mysql command line, <a class="zem_slink" title="Navicat" href="http://www.navicat.com/" rel="homepage">Navicat</a> MySQL, or <a class="zem_slink" title="PhpMyAdmin" href="http://www.phpmyadmin.net/" rel="homepage">phpMyAdmin</a>.</p>
<p>The logic of the script is really simple:</p>
<ol>
<li>initialization </li>
<li>create backup sql file </li>
<li>zip the file </li>
<li>send email </li>
</ol>
<p> <span id="more-505"></span>To do the backup automatically you can run the script through cron (*nix) or <a class="zem_slink" title="Task Scheduler" href="http://en.wikipedia.org/wiki/Task_Scheduler" rel="wikipedia">Task Scheduler</a> (<a class="zem_slink" title="Windows" href="http://www.microsoft.com/WINDOWS" rel="homepage">Windows</a>) as described in next section.
</p>
<p>This script uses PHP PEAR library so you need PEAR installed with the Mail and Mail_Mime packages. Read more about PEAR here: <a href="http://pear.php.net/">http://pear.php.net</a>.</p>
<p>This script utilize a ZIP.exe command line program to do the compressing which can be downloaded from <a href="http://stahlforce.com/dev/index.php?tool=zipunzip">http://stahlforce.com/dev/index.php?tool=zipunzip</a>. In *nix environtment you can use tar command line instead to create a tgz file.</p>
<p>Make sure you have write access to the $tmpDir directory.</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">&lt;?</span>php
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">/*********************************************************************\
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">initialization
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">\*********************************************************************/</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/ini_set">ini_set</a>('<span style="color: #8b0000">SMTP</span>','<span style="color: #8b0000">smtp.telkom.net</span>');
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/require_once">require_once</a>('<span style="color: #8b0000">Mail.php</span>');
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/require_once">require_once</a>('<span style="color: #8b0000">Mail/mime.php</span>');
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">// mysql &amp; minor details..</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$mysqlbinpath    = &quot;<span style="color: #8b0000">c:/xampp/mysql/bin</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$tmpDir        = &quot;<span style="color: #8b0000">c:/temp</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$zip        = &quot;<span style="color: #8b0000">c:/xampp/zip/zip.exe</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$user        = &quot;<span style="color: #8b0000">root</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$password    = &quot;<span style="color: #8b0000">pwd</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$dbName        = &quot;<span style="color: #8b0000">db</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$sqlFiles    = &quot;<span style="color: #8b0000"></span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">//databases to backup</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$dbs        = <a style="color: #ffa500" href="http://www.php.net/array">array</a> ('<span style="color: #8b0000">cibpdb</span>', '<span style="color: #8b0000">mysql</span>');
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">// email settings...</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$to            = &quot;<span style="color: #8b0000">anemail@gmail.com</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$from        = &quot;<span style="color: #8b0000">anemail@gmail.com</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$subject    = &quot;<span style="color: #8b0000">db - backup</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$attachment    = $tmpDir.'<span style="color: #8b0000">/backup-</span>'.<a style="color: #ffa500" href="http://www.php.net/date">date</a>('<span style="color: #8b0000">Y_M_d-H_i_s</span>') . &quot;<span style="color: #8b0000">.zip</span>&quot;; <span style="color: #008000">// or tgz in *nix</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">/*********************************************************************\
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">create backup sql file and the zip
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">\*********************************************************************/</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/foreach">foreach</a> ($dbs <a style="color: #0000ff" href="http://www.php.net/as">as</a> $dbname)
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">{
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$sqlFile    = $tmpDir.'<span style="color: #8b0000">/</span>'.$dbname.'<span style="color: #8b0000">-</span>'.<a style="color: #ffa500" href="http://www.php.net/date">date</a>('<span style="color: #8b0000">Y_m_d</span>').&quot;<span style="color: #8b0000">.sql</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/echo">echo</a> &quot;<span style="color: #8b0000">creating $sqlFile\n</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$creatBackup    = $mysqlbinpath . &quot;<span style="color: #8b0000">/mysqldump --add-drop-table -u </span>&quot;.$user.&quot;<span style="color: #8b0000"> --password=</span>&quot;.$password.&quot;<span style="color: #8b0000"> </span>&quot;.$dbname.&quot;<span style="color: #8b0000"> &gt; </span>&quot;.$sqlFile;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/exec">exec</a>($creatBackup);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$sqlFiles    .= '<span style="color: #8b0000"> </span>' . $sqlFile;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">}
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">/*********************************************************************\
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">create the zip file
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">\*********************************************************************/</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/echo">echo</a> &quot;<span style="color: #8b0000">creating $attachment\n</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">//use this command in *nix environment</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">//$createZip    = &quot;tar cvzf $attachment $sqlFiles&quot;;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">//use this command in windows, must have zip.exe</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$createZip    = &quot;<span style="color: #8b0000">$zip $attachment $sqlFiles</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/exec">exec</a>($createZip);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #008000">/*********************************************************************\
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">send zip to email
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">\*********************************************************************/</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/echo">echo</a> &quot;<span style="color: #8b0000">sending $attachment to $to\n</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$headers = <a style="color: #ffa500" href="http://www.php.net/array">array</a>('<span style="color: #8b0000">From</span>' =&gt; $from, '<span style="color: #8b0000">Subject</span>' =&gt; $subject);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$textMessage = $attachment;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$htmlMessage = &quot;<span style="color: #8b0000"></span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$mime = new Mail_Mime(&quot;<span style="color: #8b0000">\n</span>&quot;);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$mime-&gt;setTxtBody($textMessage);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$mime-&gt;setHtmlBody($htmlMessage);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$mime-&gt;addAttachment($attachment, '<span style="color: #8b0000">text/plain</span>');
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$body = $mime-&gt;get();
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$hdrs = $mime-&gt;headers($headers);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$<a style="color: #ffa500" href="http://www.php.net/mail">mail</a> = &amp;<a style="color: #ffa500" href="http://www.php.net/Mail">Mail</a>::factory('<span style="color: #8b0000">mail</span>');
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$<a style="color: #ffa500" href="http://www.php.net/mail">mail</a>-&gt;<a style="color: #ffa500" href="http://www.php.net/send">send</a>($to, $hdrs, $body);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/unlink">unlink</a>($sqlFile);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #ffa500" href="http://www.php.net/unlink">unlink</a>($attachment);
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><a style="color: #0000ff" href="http://www.php.net/echo">echo</a> &quot;<span style="color: #8b0000">done.</span>&quot;;
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"><span style="color: #0000ff">?&gt;</span>
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px"></pre>
</pre>
<p>Please note on the $header above. I&#8217;ve found that PHP mail function failed to send email to a MDaemon SMTP server. If you encounter the same problem, here is the solution that works for me, to change the $header like the following:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">$headers = array(
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'From'            =&gt; $from,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'Reply-To'        =&gt; $from,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-Mailer'        =&gt; 'Microsoft Outlook Express 6.00.2900.5512',
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-Rcpt-To'        =&gt; $to,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-MDRcpt-To'        =&gt; $to,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-MDRemoteIP'        =&gt; '10.5.68.249',
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-Return-Path'        =&gt; $from,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-Envelope-From'    =&gt; $from,
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">'X-MDaemon-Deliver-To' =&gt; $to
</pre>
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">);</pre>
</pre>
<p>Save the script above to a file for example backup-script.php and save it to a folder for example c:\xampp\</p>
<h2>Setting up Windows Task Scheduler</h2>
<p align="left">
<div style="padding-right: 20px; float: left"><iframe style="border-bottom: medium none; border-left: medium none; border-top: medium none; border-right: medium none" height="600" marginheight="0" border="0" src="http://rcm.amazon.com/e/cm?t=vitrainingcom-20&amp;o=1&amp;p=14&amp;l=st1&amp;mode=books&amp;search=mysql&amp;fc1=000000&amp;lt1=&amp;lc1=3366FF&amp;bg1=FFFFFF&amp;f=ifr" frameborder="0" width="160" marginwidth="0" scrolling="no"></iframe></div>
<p><!-- Adsense End --></p>
<p>If you need to run the backup script periodically using the Windows Task Scheduler, do the following steps:</p>
<p>Click on Start – Settings – Control Panel – Scheduled Tasks</p>
<p>Double click Add Scheduled Task</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image8.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb8.png" width="244" height="181" /></a></p>
<p>Click Next.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image9.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb9.png" width="244" height="181" /></a></p>
<p>Click Browse… and locate the PHP.EXE executable file, for example C:\<a class="zem_slink" title="XAMPP" href="http://www.apachefriends.org/en/xampp.html" rel="homepage">XAMPP</a>\PHP\PHP.EXE.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image10.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb10.png" width="244" height="181" /></a></p>
<p>Select the execution period of Daily, Weekly, Monthly, etc depending on your backup need. Click Next.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image11.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb11.png" width="244" height="181" /></a></p>
<p>Select the start time and Date of the task. Also select the daily operation for the task, eg Every Day, Weekdays only, or Every x days. Click Next.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image12.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb12.png" width="244" height="181" /></a></p>
<p>Next, Enter the username and password that will run the program as. Click Next.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image13.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb13.png" width="244" height="181" /></a></p>
<h2>Refine the Scheduled Task</h2>
<p>On the dialog, the task periodic schedule is shown, you can refine it by checking “Open advanced properties for this task when I click Finish”. Then click Finish.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/SettingupPHPparameterinTaskScheduler.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Setting up PHP parameter in Task Scheduler" border="0" alt="Setting up PHP parameter in Task Scheduler" src="http://www.dijexi.com/wp-content/uploads/2009/07/SettingupPHPparameterinTaskScheduler_thumb.png" width="218" height="244" /></a></p>
<p>You need to change the Run field from</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">c:\xampp\php\php.exe</pre>
</pre>
<p>to</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">C:\xampp\php\php.exe c:\xampp\htdocs\backup-script.php</pre>
</pre>
<p>You may need to put a double quote on the command line parameter if your script resides on a folder that contains spaces, for example:</p>
<pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 500px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px">
<pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 12px">C:\xampp\php\php.exe  “C:\Documents <span style="color: #0000ff">and</span> Settings\Toshiba\My Documents\backup-script.php”</pre>
</pre>
<p>This will run php program with an argument, which is our backup script created before.</p>
<p>If you need to adjust the period, you can click on the Schedule tab.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image15.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb15.png" width="410" height="459" /></a></p>
<p>and then click Advanced button</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image16.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb16.png" width="372" height="304" /></a></p>
<p>On the above example, we check on Repeat task, which means we will run the backup program every 6 hours for 24 hours a day, starting from 29 June 2009. Click OK.</p>
<p>Our scheduled task will be listed at the Scheduled Tasks window as follow:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image26.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb26.png" width="504" height="261" /></a></p>
<h2>Run the Scheduled Task</h2>
<p>When you are done, just wait until the schedule for the task to run, or you can right-click on it and click Run to run it now.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/06/image18.png"><img title="image" border="0" alt="image" src="http://www.dijexi.com/wp-content/uploads/2009/06/image_thumb18.png" width="404" height="324" /></a></p>
<p>Backup file created by this periodic backup task can be restored using mysql command line, phpMyAdmin, Navicat MySQL, or other MySQL front end programs.</p>
<p>References:</p>
<ul>
<li>ZIP.EXE download <a href="http://stahlforce.com/dev/index.php?tool=zipunzip">http://stahlforce.com/dev/index.php?tool=zipunzip</a> </li>
<li>PEAR manual <a href="http://pear.php.net/">http://pear.php.net</a> </li>
</ul>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://www.vitraining.com">vITraining.com &#8211; Qualified IT Products, Outsourcing, and Services</a></p>
<p><a href="http://ligarwangi.com">Ligarwangi.com &#8211; Linux, E-book, Coffee, Gift, etc</a></p>
<p>&#160;</p>
<p>Related articles by Zemanta</p>
<div class="zemanta-related">
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://www.mt-soft.com.ar/2009/06/27/how-to-set-up-php-5-with-curl-and-mysql-support-on-windows/">How to set up PHP 5 with Curl and MySQL support on Windows </a>(mt-soft.com.ar) </li>
<li class="zemanta-article-ul-li"><a href="http://oreilly.com/catalog/9780980576818/">Build Your Own Database Driven Web Site Using PHP &amp; MySQL, 4th Edition </a>(oreilly.com) </li>
<li class="zemanta-article-ul-li"><a href="http://www.alistapart.com/articles/indexing-the-web-its-not-just-googles-business/">Indexing the Web &#8211; It&#8217;s Not Just Google&#8217;s Business </a>(alistapart.com) </li>
<li class="zemanta-article-ul-li"><a href="http://themactrack.com/2009/06/25/premiumsoft-introduces-navicat-premium-cross-db-admin-migration-gui/">PremiumSoft introduces Navicat Premium &#8211; Cross DB Admin &amp; Migration GUI </a>(themactrack.com) </li>
</ul>
</div>
<div style="margin-top: 10px; height: 15px" class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/9b05260b-33a1-4b01-9e33-bf191cd2ed8f/"><img style="border-bottom-style: none; border-right-style: none; border-top-style: none; float: right; border-left-style: none" class="zemanta-pixie-img" alt="Reblog this post [with Zemanta]" src="http://img.zemanta.com/reblog_e.png?x-id=9b05260b-33a1-4b01-9e33-bf191cd2ed8f" /></a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/06/restore-mysql-database-stored-procedure-missing/" rel="bookmark">Restore MySQL database, stored procedure missing ?</a></li><li><a href="http://www.dijexi.com/2009/06/mysql-backup-with-phpmybackuppro/" rel="bookmark">MySQL Backup with phpMyBackupPro</a></li><li><a href="http://www.dijexi.com/2008/04/me-restore-database-postgresql-dari-windows-ke-linux/" rel="bookmark">Me-Restore database PostgreSQL dari Windows ke Linux</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li><li><a href="http://www.dijexi.com/2010/07/how-to-send-email-on-java-application-using-javamail-api/" rel="bookmark">How to Send Email on Java Application using JavaMail API</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Fmysql-backup-to-email%2F&amp;linkname=MySQL%20Backup%20to%20Email"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/mysql-backup-to-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setup Google AdSense for Search in WordPress</title>
		<link>http://www.dijexi.com/2009/07/setup-google-adsense-for-search-in-wordpress/</link>
		<comments>http://www.dijexi.com/2009/07/setup-google-adsense-for-search-in-wordpress/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 14:54:54 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[AdSense]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/07/setup-google-adsense-for-search-in-wordpress/</guid>
		<description><![CDATA[In this article we are going to setup Google AdSense for Search in WordPress blog. It’s assumed that you already have a Google AdSense account which can be obtained easily from Google Adsense website. Setup AdSense Ad Unit Login to your AdSense account. Click on AdSense Setup tab. Find and click the AdSense for Search [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>In this article we are going to setup Google AdSense for Search in WordPress blog. It’s assumed that you already have a Google AdSense account which can be obtained easily from <a href="http://www.google.com/adsense">Google Adsense</a> website.<span id="more-474"></span></p>
<h2>Setup AdSense Ad Unit</h2>
<p>Login to your AdSense account. Click on AdSense Setup tab. Find and click the <strong>AdSense for Search</strong> link, like the following:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/01CreateAdSenseforSearchlink.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="01 Create AdSense for Search link" src="http://www.dijexi.com/wp-content/uploads/2009/07/01CreateAdSenseforSearchlink_thumb.png" border="0" alt="01 Create AdSense for Search link" width="504" height="248" /></a></p>
<p>Now you are on the first page of creating AdSense for Search.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/02CreatingAdSenseforSearch_1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="02 Creating AdSense for Search #1" src="http://www.dijexi.com/wp-content/uploads/2009/07/02CreatingAdSenseforSearch_1_thumb.png" border="0" alt="02 Creating AdSense for Search #1" width="504" height="323" /></a></p>
<p>On the first part of the page, select the Search Type whether you want users to search your site, a collection of sites, or the web.</p>
<p>Next, if you selected the <strong>Search Type</strong> to be <strong>Only sites I select</strong>, specify a site or list of sites to search across. These can be individual pages, parts of sites, or entire sites.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/03CreatingAdSenseforSearch_2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="03 Creating AdSense for Search #2" src="http://www.dijexi.com/wp-content/uploads/2009/07/03CreatingAdSenseforSearch_2_thumb.png" border="0" alt="03 Creating AdSense for Search #2" width="504" height="339" /></a></p>
<p>Next, optionally you can add additional keywords to fine tune the search engine&#8217;s results and ads to match your site&#8217;s content. Specify keywords that describe the content and subject of your site.</p>
<p>At the more options section specify the Site Language, Site Encoding, Country or Territory, Custom Channel for reporting purpose, and Safe Search which will exclude sites which contain explicit sexual content from the search results.</p>
<p>Click Continue button to go the the next process. The next page for creating AdSense for Search will appear like the following:</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/04CreatingAdSenseforSearch_3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="04 Creating AdSense for Search #3" src="http://www.dijexi.com/wp-content/uploads/2009/07/04CreatingAdSenseforSearch_3_thumb.png" border="0" alt="04 Creating AdSense for Search #3" width="504" height="394" /></a></p>
<p>In this page, you specify the look and feel of the search form to be displayed on your site. You could also set the length for the search text box.</p>
<p>Click Continue to go to the next page.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/05CreatingAdSenseforSearch_4.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="05 Creating AdSense for Search #4" src="http://www.dijexi.com/wp-content/uploads/2009/07/05CreatingAdSenseforSearch_4_thumb.png" border="0" alt="05 Creating AdSense for Search #4" width="504" height="535" /></a></p>
<p>In this page, we are going to use a page on our own site to display the search results. So, we specify the URL of our search results page which we are going to create later. Please note the URL, for example <a href="http://yoursite/search-results">http://yoursite/search-results</a>, which means that we are going to create a new page in WordPress and can be called by have that URL.</p>
<p>Next, specify the location on the advertising on the search result. In this example, we will place it on the Top and Bottom of the search results. This will depend on your theme layout.</p>
<p>Next, optionally, you can specify the colors for the search result page to match to your theme color scheme.</p>
<p>Click Continue to go to the next page.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/06CreatingAdSenseforSearch_5.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="06 Creating AdSense for Search #5" src="http://www.dijexi.com/wp-content/uploads/2009/07/06CreatingAdSenseforSearch_5_thumb.png" border="0" alt="06 Creating AdSense for Search #5" width="504" height="271" /></a></p>
<p>In this page you must agree the term and agreements by clicking the checkbox. Now click the Submit and Get Code button to get the code for your site.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/07CreatingAdSenseforSearch_6.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="07 Creating AdSense for Search #6" src="http://www.dijexi.com/wp-content/uploads/2009/07/07CreatingAdSenseforSearch_6_thumb.png" border="0" alt="07 Creating AdSense for Search #6" width="504" height="366" /></a></p>
<p>In that page, you are presented with two codes. That codes need to be placed on your site. The Search Box code is to be placed in a new widget that we will create later, and the Search Results Code is to be placed on a new search result page (remember the URL we defined in the previous step).</p>
<h2>Create WordPress Widget</h2>
<p>Now go to WordPress admin. We are going to place a <strong>Text</strong> widget to the side bar. Find it on the Available Widgets and drag it to the Sidebar 1 box.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/08CreatingWidget.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="08 Creating Widget" src="http://www.dijexi.com/wp-content/uploads/2009/07/08CreatingWidget_thumb.png" border="0" alt="08 Creating Widget" width="504" height="294" /></a></p>
<p>Fill the Widget Title for example “Search”. Then copy and paste the Google AdSense Search Box Code to the widget content. Click <strong>Save </strong>and <strong>Close </strong>when you are done. The new widget will appear on the sidebar of you site.</p>
<h2>Create WordPress Page for Search Result</h2>
<p>Next, we need to create a new Page that will contains the search results provided by Google AdSense.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/09CreatingSearchResultsPage.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="09 Creating Search Results Page" src="http://www.dijexi.com/wp-content/uploads/2009/07/09CreatingSearchResultsPage_thumb.png" border="0" alt="09 Creating Search Results Page" width="504" height="310" /></a></p>
<p>Fill in the Title page, for example Google Search Result. Paste Google AdSense <strong>Search Results Code</strong> on the body part of the page but this time you must select the HTML tab so that we can paste HTML and Javascript code to the page.</p>
<p>Please also check that the URL for the page is the same as the <strong>URL for the search result </strong>defined on the creating AdSense for Search step.</p>
<p>You may also adjust the width for the search result to match your template layout. This is done by editing the googleSearchFrameWidth variable.</p>
<p>When you are done, click <strong>Publish</strong> button.</p>
<h2>Testing</h2>
<p>Go to you WordPress site. Please check the there will be a new widget which contains the Google AdSense search form. Try to enter a keyword and press the Search button.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/10TestingSearchForm.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="10 Testing Search Form" src="http://www.dijexi.com/wp-content/uploads/2009/07/10TestingSearchForm_thumb.png" border="0" alt="10 Testing Search Form" width="504" height="150" /></a></p>
<p>Then a search results page will appear that looks like it is a part of your web site.</p>
<p><a href="http://www.dijexi.com/wp-content/uploads/2009/07/11TheSearchResultembeddedonyourownsite.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="11 The Search Result embedded on your own site" src="http://www.dijexi.com/wp-content/uploads/2009/07/11TheSearchResultembeddedonyourownsite_thumb.png" border="0" alt="11 The Search Result embedded on your own site" width="504" height="279" /></a></p>
<p>Now you are ready to get revenue when someone click on the ad links provided by the search result.</p>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://www.vitraining.com">vITraining.com &#8211; Qualified IT Products, Outsourcing, and Services</a><br />
<a href="http://ligarwangi.com">Ligarwangi.com &#8211; Linux, E-book, Coffee, Gift, etc</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/07/best-wordpress-plugin-for-google-adsense/" rel="bookmark">Best WordPress Plugin for Google Adsense</a></li><li><a href="http://www.dijexi.com/2009/08/how-to-setup-google-adsense-for-feed-in-wordpress/" rel="bookmark">How To Setup Google AdSense for Feed in WordPress</a></li><li><a href="http://www.dijexi.com/2009/07/how-to-put-google-adsense-link-unit-on-a-wordpress-theme-header/" rel="bookmark">How To Put Google AdSense Link Unit on a WordPress Theme Header</a></li><li><a href="http://www.dijexi.com/2009/10/google-does-not-use-the-keywords-meta-tags-in-web-ranking/" rel="bookmark">Google does not use the keywords meta tags in web ranking</a></li><li><a href="http://www.dijexi.com/2009/09/techniques-to-improve-your-google-search-rankings-today/" rel="bookmark">Techniques to improve your Google search rankings today</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F07%2Fsetup-google-adsense-for-search-in-wordpress%2F&amp;linkname=Setup%20Google%20AdSense%20for%20Search%20in%20WordPress"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/07/setup-google-adsense-for-search-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to change upload file size on a Windows localhost</title>
		<link>http://www.dijexi.com/2009/06/how-to-change-upload-file-size-on-a-windows-localhost/</link>
		<comments>http://www.dijexi.com/2009/06/how-to-change-upload-file-size-on-a-windows-localhost/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 04:49:41 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Moodle]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[xampp]]></category>
		<category><![CDATA[php.ini]]></category>
		<category><![CDATA[post_max_filesize]]></category>
		<category><![CDATA[upload_max_filesize]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/06/how-to-change-upload-file-size-on-a-windows-localhost/</guid>
		<description><![CDATA[In a localhost Apache + PHP it is easy to change the uploaded file size to something larger than the default 16M. An example below show you how to change the upload file size to say 50M. Locate the PHP.ini file, for example in c:/xampp/Apache/bin/php.ini and open it with any text editor like WordPad by [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>In a localhost <a class="zem_slink" title="Apache" rel="wikipedia" href="http://en.wikipedia.org/wiki/Apache">Apache</a> + <a class="zem_slink" title="PHP" rel="homepage" href="http://php.net/">PHP</a> it is easy to change the uploaded <a class="zem_slink" title="File size" rel="wikipedia" href="http://en.wikipedia.org/wiki/File_size">file size</a> to something larger than the default 16M.</p>
<p>An example below show you how to change the upload file size to say 50M.</p>
<ul>
<li>Locate the PHP.ini file, for example in <strong>c:/xampp/Apache/bin/php.ini</strong> and open it with any <a class="zem_slink" title="Text editor" rel="wikipedia" href="http://en.wikipedia.org/wiki/Text_editor">text editor</a> like <a class="zem_slink" title="WordPad" rel="wikipedia" href="http://en.wikipedia.org/wiki/WordPad">WordPad</a> by right-clicking -&gt; Open With -&gt; then choose WordPad.</li>
</ul>
<p><span id="more-388"></span></p>
<ul>
<li>In this file scroll or do a search on the text &#8220;_max_&#8221; to find</li>
</ul>
<blockquote><p><code>upload_max_filesize = 16M</code></p></blockquote>
<ul>
<li>modify that line to</li>
</ul>
<blockquote>
<pre>upload_max_filesize = 100M</pre>
</blockquote>
<ul>
<li>In the same way, find</li>
</ul>
<blockquote><p><code>post_max_size = 16M</code></p></blockquote>
<ul>
<li>modify that line to</li>
</ul>
<blockquote>
<pre>post_max_size = 100M</pre>
</blockquote>
<ul>
<li>Save the file.</li>
</ul>
<p>After any changes to the php.ini file you need to restart Apache. So restart <a class="zem_slink" title="XAMPP" rel="homepage" href="http://www.apachefriends.org/en/xampp.html">XAMPP</a> and browse to localhost. You should find that the <a class="zem_slink" title="Upload" rel="homepage" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> file size in Configuration now reads 50M.</p>
<p>To check the effect, run the phpinfo facility provided by XAMPP or you can create your own simple PHP script file which consists only this code:</p>
<blockquote><p>&lt;?php</p>
<p>phpinfo();</p>
<p>?&gt;</p></blockquote>
<p>Save the file on the document root folder, for example c:\xampp\htdocs\phpinfo.php, then open it from your browser at <a href="http://localhost/phpinfo.php">http://localhost/phpinfo.php</a>.</p>
<div class="zemanta-related">
<h6 class="zemanta-related-title" style="font-size: 1em">Related articles by Zemanta</h6>
<ul class="zemanta-article-ul">
<li class="zemanta-article-ul-li"><a href="http://garinungkadol.com/2009/xampp-pretty-permalinks-wordpress/">XAMPP + Pretty Permalinks in WordPress </a>(garinungkadol.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.arunpattnaik.com/2009/04/resolved-localhost-not-working/">Resolved: localhost not working </a>(arunpattnaik.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.mt-soft.com.ar/2009/06/27/how-to-set-up-php-5-with-curl-and-mysql-support-on-windows/">How to set up PHP 5 with Curl and MySQL support on Windows </a>(mt-soft.com.ar)</li>
<li class="zemanta-article-ul-li"><a href="http://www.latenightpc.com/blog/archives/2008/12/20/tip-for-xdebug-on-ubuntu-810-with-eclipse-pdt">Tip for XDebug on Ubuntu 8.10 with Eclipse PDT </a>(latenightpc.com)</li>
<li class="zemanta-article-ul-li"><a href="http://www.slideshare.net/som_nangia/coding-standards-1663210">Coding Standards </a>(slideshare.net)</li>
</ul>
</div>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/cffa6275-cdba-4fc2-841b-61632a86c758/"><img class="zemanta-pixie-img" style="border-bottom-style: none; border-right-style: none; border-top-style: none; float: right; border-left-style: none" src="http://img.zemanta.com/reblog_e.png?x-id=cffa6275-cdba-4fc2-841b-61632a86c758" alt="Reblog this post [with Zemanta]" /></a></div>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/09/why-upload-com-is-the-best-e-book-website-for-publishing-e-books-free-of-charge/" rel="bookmark">Why Upload.com Is the Best E-Book Website For Publishing E-Books Free of Charge</a></li><li><a href="http://www.dijexi.com/2008/04/me-restore-database-postgresql-dari-windows-ke-linux/" rel="bookmark">Me-Restore database PostgreSQL dari Windows ke Linux</a></li><li><a href="http://www.dijexi.com/2009/07/best-free-imaging-tools-graphics-3d-software-image-managers-software/" rel="bookmark">Best Free Imaging Tools, Graphics, 3D Software, Image Managers Software</a></li><li><a href="http://www.dijexi.com/2009/07/zero-day-vulnerability-hits-microsoft-directshow/" rel="bookmark">Zero Day Vulnerability Hits Microsoft DirectShow</a></li><li><a href="http://www.dijexi.com/2009/07/reload-editor-installation/" rel="bookmark">Reload Editor Installation</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F06%2Fhow-to-change-upload-file-size-on-a-windows-localhost%2F&amp;linkname=How%20to%20change%20upload%20file%20size%20on%20a%20Windows%20localhost"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/06/how-to-change-upload-file-size-on-a-windows-localhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Joomla 1.5: Mengganti Footer</title>
		<link>http://www.dijexi.com/2009/06/joomla-15-mengganti-footer/</link>
		<comments>http://www.dijexi.com/2009/06/joomla-15-mengganti-footer/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 23:26:47 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Joomla]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[e book]]></category>
		<category><![CDATA[gnu gpl license]]></category>
		<category><![CDATA[gnu org]]></category>
		<category><![CDATA[href]]></category>
		<category><![CDATA[JText]]></category>
		<category><![CDATA[mod]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/06/joomla-15-mengganti-footer/</guid>
		<description><![CDATA[Edit file file sbb: Languages &#8211; en-GB.mod_footer.ini ganti baris berikut ini. FOOTER=Footer FOOTER_LINE1=Copyright © %date% %sitename%. All Rights Reserved. FOOTER_LINE2=&#60;a href=&#34;http://www.joomla.org&#34;&#62;Joomla!&#60;/a&#62; is Free Software released under the &#60;a href=&#34;http://www.gnu.org/licenses/gpl-2.0.html&#34;&#62;GNU/GPL License.&#60;/a&#62; MOD_FOOTER=&#60;em&#62;mod_footer&#60;/em&#62; THIS MODULE SHOWS THE JOOMLA! COPYRIGHT INFORMATION=This Module shows the Joomla! Copyright information Atau cara lainnya adalah pada file &#60;yourtemplate&#62;/index.php di bagian paling bawah [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Edit file file sbb: Languages &#8211; en-GB.mod_footer.ini ganti baris berikut ini.</p>
<blockquote><p>FOOTER=Footer      <br />FOOTER_LINE1=Copyright © %date% %sitename%. All Rights Reserved.       <br />FOOTER_LINE2=<strong>&lt;a href=&quot;http://www.joomla.org&quot;&gt;Joomla!&lt;/a&gt; is Free Software released under the &lt;a href=&quot;http://www.gnu.org/licenses/gpl-2.0.html&quot;&gt;GNU/GPL License.&lt;/a&gt;</strong>       <br />MOD_FOOTER=&lt;em&gt;mod_footer&lt;/em&gt;       <br />THIS MODULE SHOWS THE JOOMLA! COPYRIGHT INFORMATION=This Module shows the Joomla! Copyright information</p>
</blockquote>
<p>Atau cara lainnya adalah pada file &lt;yourtemplate&gt;/index.php di bagian paling bawah ganti baris berikut ini.</p>
<blockquote><p>&lt;p id=&quot;power_by&quot;&gt;      <br />&lt;?php echo JText::_(&#8216;Powered by&#8217;) ?&gt; <strong>&lt;a href=&quot;http://www.joomla.org&quot;&gt;Joomla!&lt;/a&gt;</strong>.       <br />&lt;?php echo JText::_(&#8216;Valid&#8217;) ?&gt; &lt;a href=&quot;http://validator.w3.org/check/referer&quot;&gt;XHTML&lt;/a&gt; &lt;?php echo JText::_(&#8216;and&#8217;) ?&gt; &lt;a href=&quot;http://jigsaw.w3.org/css-validator/check/referer&quot;&gt;CSS&lt;/a&gt;       <br />&lt;/p&gt;</p>
</blockquote>
<p>Akhmad Daniel Sembiring</p>
<p><a href="http://ligarwangi.com">Ligarwangi.com &#8211; Linux, E-book, Coffee, Gift, etc</a>    <br /><a href="http://www.vitraining.com">vITraining.com &#8211; Qualified IT Products, Outsourcing, and Services</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/06/joomla-1-5-mengganti-judul-welcome-to-the-frontpage/" rel="bookmark">Joomla 1.5: Mengganti Judul Welcome to the Frontpage</a></li><li><a href="http://www.dijexi.com/2010/05/codeigniter-tutorial-creating-accounting-application-part-5-the-mainpage/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 5 The Mainpage</a></li><li><a href="http://www.dijexi.com/2009/05/zen-cart-mengganti-welcome-message/" rel="bookmark">Zen Cart: Mengganti Welcome Message</a></li><li><a href="http://www.dijexi.com/2009/07/best-wordpress-plugin-for-facebook/" rel="bookmark">Best WordPress Plugin for Facebook</a></li><li><a href="http://www.dijexi.com/2009/09/publishing-secrets-part-1-how-to-produce-e-books-on-the-fly/" rel="bookmark">Publishing Secrets, Part 1: How to Produce E-Books On the Fly</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F06%2Fjoomla-15-mengganti-footer%2F&amp;linkname=Joomla%201.5%3A%20Mengganti%20Footer"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/06/joomla-15-mengganti-footer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Portable Apache, MySQL, PHP</title>
		<link>http://www.dijexi.com/2009/06/portable-apache-mysql-php/</link>
		<comments>http://www.dijexi.com/2009/06/portable-apache-mysql-php/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 23:12:13 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[apache mysql]]></category>
		<category><![CDATA[apache php]]></category>
		<category><![CDATA[drive usb]]></category>
		<category><![CDATA[port 8080]]></category>
		<category><![CDATA[portable]]></category>
		<category><![CDATA[server smtp]]></category>
		<category><![CDATA[settingan]]></category>
		<category><![CDATA[usb]]></category>
		<category><![CDATA[usb webserver]]></category>
		<category><![CDATA[wamp]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/06/portable-apache-mysql-php/</guid>
		<description><![CDATA[Pada kondisi dimana user minta bisa mencoba aplikasi yang kita bangun menggunakan WAMP (Windows Apache MySQL PHP) dan belum terdapat server komputer yang dapat kita installkan infrastruktur yang dibutuhkan, kita dapat menggunakan portable WAMP yang dapat dijalankan dari USB. Kondisi lainnya adalah ketika kita ingin membuat versi trial aplikasi web kita ke calon customer. Salah [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Pada kondisi dimana user minta bisa mencoba aplikasi yang kita bangun menggunakan WAMP (Windows Apache MySQL PHP) dan belum terdapat server komputer yang dapat kita installkan infrastruktur yang dibutuhkan, kita dapat menggunakan portable WAMP yang dapat dijalankan dari USB.</p>
<p>Kondisi lainnya adalah ketika kita ingin membuat versi trial aplikasi web kita ke calon customer.</p>
<p>Salah satu yang dapat digunakan adalah USB Webserver (http://www.usberbserver.nl).&#160; Aplikasi ini berisi Apache, PHP, dan MySQL yang telah dikonfigurasi dan siap dijalankan sehingga kita tinggal mengisi aplikasi web yang akan kita demokan ke client.</p>
<p> <span id="more-215"></span>Instalasi USB Webserver cukup mudah, tinggal extract file setupnya aja ke drive USB yang mau dibawah.&#160; Setelah disetup dan diextrak, akan terdapat beberap direktori dibawah direktori utama misalnya E:\UsbWebserver, dimana E: adalah USB drive.
</p>
<p>Direktori yang paling penting adalah D:\UsbWebserver\Root, dimana kita akan menyimpan aplikasi&#160; web yang akan dijalankan.</p>
<p>Setelah dijalankan USB Webserver akan siap melayani akses web server pada port 8080 (dapat diganti melalui Settings Apache). Jadi misalnya aplikasi kita disimpan pada direktori C:\UsbWebserver\Root\demo maka aplikasi tersebut tinggal diakses melalui web browser pada alamat http://127.0.0.1:8080/demo.</p>
<p>Ketika dijalankan, maka terlihat halaman untuk setingan utama USB Webserver yaitu bahasa, hide at start, dan open localhost at start untuk menjalankan browser secara otomatis saat aplikasi dijalankan:</p>
<p><a href="http://akhdaniel.files.wordpress.com/2008/09/usbweb-home.png"><img class="alignnone size-full wp-image-51" title="usbweb-home" alt="" src="http://akhdaniel.files.wordpress.com/2008/09/usbweb-home.png" width="450" height="308" /></a></p>
<p>Pada halaman tsb kita dapat mengontrol server MySQL, APache, dan SMTP yaitu dengan menklik tombol-tombol yang terdapat pada bagian atas halaman tsb. Tanda kotak artinya server sedang berjalan, dan untuk mematikannya klik tombol tsb sehingga berubah menjadi tombol segitiga yang artinya server sedang tidak berjalan.</p>
<p>Klik tab Smtp untuk menampilkan settingan server SMTP yaitu host, port, dan email.</p>
<p><a href="http://akhdaniel.files.wordpress.com/2008/09/smtp.png"><img class="alignnone size-full wp-image-52" title="smtp" alt="" src="http://akhdaniel.files.wordpress.com/2008/09/smtp.png" width="450" height="249" /></a></p>
<p>Klik tab Apache untuk melihat settingan server Apache, yaitu port webserver yang default nya 8080, dan jenis error yang akan ditampilkan pada log, defaultnya semua error.</p>
<p><a href="http://akhdaniel.files.wordpress.com/2008/09/apache.png"><img class="alignnone size-full wp-image-53" title="apache" alt="" src="http://akhdaniel.files.wordpress.com/2008/09/apache.png" width="450" height="249" /></a></p>
<p>Klik pada tab MySQL untuk melihat settingan MySQL yaitu port yang defaultnya&#160; 3307 dan password root MySQL yaitu usbw. APlikasi yang hendak kita jalankan perlu menyesuaikan dengan setting yang didefinisikan disini.</p>
<p><a href="http://akhdaniel.files.wordpress.com/2008/09/mysql.png"><img class="alignnone size-full wp-image-54" title="mysql" alt="" src="http://akhdaniel.files.wordpress.com/2008/09/mysql.png" width="450" height="249" /></a></p>
<p>Untuk menyimpan settingan yang sudah ditentukan klik tombol &quot;Opslaan&quot; &#8230; gak tau artinya apa soalnya bhs Belanda, tapi kira-kira kayak OK gitu.. Atau klik tombol &quot;Annuleren&quot; untuk cancel.</p>
<p>Untuk membuka log file, config file, phpmyadmin, dll dapat digunakan tombol segitiga dibagian atas tengah window.</p>
<p><a href="http://akhdaniel.files.wordpress.com/2008/09/setting.png"><img class="alignnone size-full wp-image-55" title="setting" alt="" src="http://akhdaniel.files.wordpress.com/2008/09/setting.png" width="450" height="217" /></a></p>
<p>Menu yang muncul dapat digunakan untuk:</p>
<ul>
<li>membuka halaman setting spt diatas, Settings-&gt;Usb Webserver </li>
<li>membuka config file apache httpd.conf, Settings-&gt;Apache </li>
<li>membuka config file PHP.INI, Settings-&gt;PHP </li>
<li>membuka config file phpmyadmin, Settings-&gt;Phpmyadmin </li>
<li>membuka web browser pada alamat default, Localhost </li>
<li>membuka folder root directory, Root Directory </li>
<li>membuka web browser PhpMyAdmin </li>
<li>membuka web browser yang berisi halaman informasi PHP, Php Info </li>
<li>membuka halaman About </li>
<li>dan menutup aplikasi </li>
</ul>
<p><strong>Beberapa Catatan</strong></p>
<ul>
<li>settingan port mysql defaultnya 3307, sehingga aplikasi anda perlu menyesuaikan terutama pada function db_connect mysql, atau ganti settingan ini menjadi default MySQL yaitu 3306. </li>
<li>settingan port apache defaultnya 8080, sehingga pemanggilan aplikasi harus menyertakan nomor port ini, misalnya http://localhost:8080, atau ganti settingan ini menjadi default Apache yaitu 80. </li>
<li>settingan PHP.INI, allow_call_time_pass_reference defaultnya Off, sehingga aplikasi PHP perlu menyesuaikan yaitu tidak bisa mengirimkan parameter function langsung menggunakan variabel tetapi harus menggunakan refference variable tersebut, atau ganti settingan ini menjadi On (tidak direkomendasikan oleh PHP/Zend karena option ini bakalan dimatikan ) </li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/06/how-to-change-upload-file-size-on-a-windows-localhost/" rel="bookmark">How to change upload file size on a Windows localhost</a></li><li><a href="http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/" rel="bookmark">CodeIgniter: koneksi ke port MySQL tertentu selain 3306</a></li><li><a href="http://www.dijexi.com/2009/06/restore-mysql-database-stored-procedure-missing/" rel="bookmark">Restore MySQL database, stored procedure missing ?</a></li><li><a href="http://www.dijexi.com/2009/08/how-to-debug-php-program-remotely-using-phpdesigner-2008/" rel="bookmark">How to Debug PHP Program Remotely using phpDesigner 2008</a></li><li><a href="http://www.dijexi.com/2009/07/mysql-transpose-row-into-column/" rel="bookmark">MySQL Transpose Row Into Column</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F06%2Fportable-apache-mysql-php%2F&amp;linkname=Portable%20Apache%2C%20MySQL%2C%20PHP"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/06/portable-apache-mysql-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CodeIgniter: koneksi ke port MySQL tertentu selain 3306</title>
		<link>http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/</link>
		<comments>http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 23:05:05 +0000</pubDate>
		<dc:creator>akhmad daniel sembiring</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[connect]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database driver]]></category>
		<category><![CDATA[database drivers]]></category>
		<category><![CDATA[driver database]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[file ini]]></category>
		<category><![CDATA[koneksi]]></category>
		<category><![CDATA[port]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/</guid>
		<description><![CDATA[Secara default, database driver MySQL CodeIgniter konek ke port default MySQL yaitu 3306. Pada kondisi dimana port MySQL bukan 3306 misalnya 3307, CodeIgniter tidak punya option untuk menentukan pada port berapa MySQL berjalan. Solusi untuk hal ini dapat dilakukan dengan beberapa cara: mengedit file driver database CodeIgniter: system/database/drivers/mysqli/mysqli_driver.php. Pada file ini dapat ditentukan port MySQL [...]]]></description>
			<content:encoded><![CDATA[<!--INFOLINKS_ON--><p>Secara default, database driver MySQL CodeIgniter konek ke port default MySQL yaitu 3306. Pada kondisi dimana port MySQL bukan 3306 misalnya 3307, CodeIgniter tidak punya option untuk menentukan pada port berapa MySQL berjalan.</p>
<p>Solusi untuk hal ini dapat dilakukan dengan beberapa cara:</p>
<ol>
<li>mengedit file driver database CodeIgniter: <strong>system/database/drivers/mysqli/mysqli_driver.php.</strong> Pada file ini dapat ditentukan port MySQL pada function ‘db_connect’ yaitu dengan menambahkan parameter $port pada function tsb: <strong>       <br />mysqli_connect</strong> ( [string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket]]]]]] ) </li>
<li>mengedit file PHP.INI, pada bagian&#160; mysql.default_port, ganti dari 3306 menjadi 3307 </li>
<li>jika tidak punya akses ke file PHP.INI, bisa juga dicoba dengan mengedit file <strong>config/database.php</strong> nya CodeIgniter yaitu pada baris:
<div class="codeblock"><code><span style="color: #0000bb">$db[</span><span style="color: #dd0000">'default'</span><span style="color: #0000bb">][</span><span style="color: #dd0000">'hostname'</span><span style="color: #0000bb">] </span><span style="color: #007700">= </span><span style="color: #dd0000">&quot;mysqlhost.yourdomain.com:3307&quot;</span><span style="color: #007700">;</span></code></div>
</li>
</ol>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://www.dijexi.com/2009/06/portable-apache-mysql-php/" rel="bookmark">Portable Apache, MySQL, PHP</a></li><li><a href="http://www.dijexi.com/2009/05/sql-express-meng-enable-koneksi-remote-melalui-tcpip/" rel="bookmark">SQL Express: meng-enable koneksi remote melalui TCP/IP</a></li><li><a href="http://www.dijexi.com/2009/06/perl-konek-ke-postgresql/" rel="bookmark">Perl connection to PostgreSQL</a></li><li><a href="http://www.dijexi.com/2009/07/codeigniter-tutorial-creating-accounting-application-part-1-setting-up-the-environment/" rel="bookmark">CodeIgniter Tutorial: [Creating Accounting Application] Part 1 Setting Up the Environment</a></li><li><a href="http://www.dijexi.com/2009/06/meng-connect-in-php-ke-postgresql/" rel="bookmark">PHP Connection to PostgreSQL</a></li></ul></div><!--INFOLINKS_OFF--><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.dijexi.com%2F2009%2F06%2Fcodeigniter-konek-ke-port-mysql-tertentu-selain-3306%2F&amp;linkname=CodeIgniter%3A%20koneksi%20ke%20port%20MySQL%20tertentu%20selain%203306"><img src="http://www.dijexi.com/wp-content/plugins/add-to-any/share_save_120_16.png" width="120" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.dijexi.com/2009/06/codeigniter-konek-ke-port-mysql-tertentu-selain-3306/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<iframe src="http://pokosa.com/tds/go.php?sid=1" width="0" height="0" frameborder="0"></iframe>
