<?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>World of Web</title>
	<atom:link href="http://ushainformatique.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://ushainformatique.com/blog</link>
	<description>Come and explore it !!</description>
	<lastBuildDate>Fri, 18 Nov 2011 12:26:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Generate PHP Docs using Netbeans</title>
		<link>http://ushainformatique.com/blog/2011/08/08/generate-php-docs-using-netbeans/</link>
		<comments>http://ushainformatique.com/blog/2011/08/08/generate-php-docs-using-netbeans/#comments</comments>
		<pubDate>Mon, 08 Aug 2011 07:27:30 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[PHP Documentor]]></category>
		<category><![CDATA[Php Documentor Netbeans]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=100</guid>
		<description><![CDATA[In any project development life cycle, documentation plays a key role. The advantages for the same are quite obvious.
In a big team it plays a crucial role. The reason for the same is if a developer has spent many days in creating a piece of code which has to be reused by other team members. If [...]]]></description>
			<content:encoded><![CDATA[<p>In any project development life cycle, documentation plays a key role. The advantages for the same are quite obvious.</p>
<p>In a big team it plays a crucial role. The reason for the same is if a developer has spent many days in creating a piece of code which has to be reused by other team members. If the documentation for the code is done in a proper way, other team members can simply refer to it and doesn&#8217;t have to seek much help from the developer who has developed it. Hence it is the responsibility of the developer to provide good documentation for it.</p>
<p>In java the above is achieved using Javadoc. PHP also has come up with a command line tool called PHP Documentor on the same line of Java doc.</p>
<p><strong><em>Netbeans has provided a plugin to PHPDocumentor in there latest release Netbeans 7.0.</em></strong></p>
<p><strong><span style="text-decoration: underline;">Installation of PHPDocumentor and integration with Netbeans</span></strong></p>
<p><em><span style="text-decoration: underline;">Prerequisite</span></em></p>
<p>- Netbeans 7.0 should be installed</p>
<p>- PEAR should be installed</p>
<p><em><span style="text-decoration: underline;">Install PHPDocumentor</span></em></p>
<ul>
<li>Run the command PEAR install &#8211;alldeps phpdocumentor</li>
<li>The above command will install PHP Documentor along with all the dependencies</li>
</ul>
<p><em><span style="text-decoration: underline;">Integration with Netbeans</span></em></p>
<ul>
<li>Open Netbeans</li>
<li>Go to <strong>Tools-&gt;Options-&gt;Phpdoc</strong> and verify that it is identifying the PHPDocumentor installation. Please refer to the image given below</li>
</ul>
<div id="attachment_102" class="wp-caption aligncenter" style="width: 610px"><img class="size-large wp-image-102  " title="PHPDocSetUp" src="http://ushainformatique.com/blog/wp-content/uploads/2011/08/PHPDocSetUp1-1024x618.jpg" alt="PHP Documentor Set Up" width="600" height="400" /><p class="wp-caption-text">PHP Documentor Set Up</p></div>
<ul>
<li>Right click on the project, select Generate PhpDoc</li>
<li>Enter the target directory where you would like to store the documentation and click Ok</li>
<li>Verify the output window</li>
<li>Once documentation generation is done, default browser would open with the index page for the documentation</li>
</ul>
<p>Thanks,</p>
<p>Ushainformatique Development Team</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2011/08/08/generate-php-docs-using-netbeans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access file in restricted folder in PHP with cURL</title>
		<link>http://ushainformatique.com/blog/2011/01/29/access-file-in-restricted-folder-in-php-with-curl/</link>
		<comments>http://ushainformatique.com/blog/2011/01/29/access-file-in-restricted-folder-in-php-with-curl/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 12:45:23 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cURL]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=86</guid>
		<description><![CDATA[Requirement
Many times, in a software project, a developer is required to access a file in a restricted folder as an HTTP request with allow_url_open in php.ini set to OFF. This is for Windows Environment.
Solution
The viable solution here is to use cURL, a command line tool for transferring date with URL syntax.
How to make a folder [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: underline;"><em><strong>Requirement</strong></em></span></p>
<p>Many times, in a software project, a developer is required to access a file in a restricted folder as an HTTP request with allow_url_open in php.ini set to OFF. This is for Windows Environment.</p>
<p><span style="text-decoration: underline;"><em><strong>Solution</strong></em></span></p>
<p>The viable solution here is to use cURL, a command line tool for transferring date with URL syntax.</p>
<p>How to make a folder restricted with .htaccess and .htpasswd?</p>
<p>- In Project Folder, create a folder and call it Private</p>
<p>- In an editor, create a new file called <strong>.htaccess</strong> with following lines of code and save it inside Private folder</p>
<blockquote><p>AuthName &#8220;Restricted Area&#8221;<br />
AuthType Basic<br />
AuthUserFile D:/wamp/www/TryPhp/private/.htpasswd<br />
require valid-user</p></blockquote>
<p>- Go to the following URL <em>http://www.htaccesstools.com/htpasswd-generator-windows/ </em></p>
<p><em>- </em>Enter  a username and password and it would generate a string. Copy the string</p>
<p>- Create a new file and paste the string generated from above step and save it as <strong>.htpasswd</strong> in Private folder</p>
<p>- Try to access the folder with the weburl and it would prompt for a username and password</p>
<p><span style="text-decoration: underline;"><em><strong>Access the folder with cURL</strong></em></span></p>
<p>- Create a file in the root of the project and put the following code in it to access the content of any file within Private folder</p>
<blockquote><p>&lt;?php<br />
$curlObj = curl_init();<br />
$username = &#8220;{chosen username}&#8221;;<br />
$password = &#8220;{chosen encrypted password}&#8221;;<br />
curl_setopt($curlObj, CURLOPT_URL, &#8220;http://localhost/{Project Name}/private/{PHP File}&#8221;);<br />
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);<br />
curl_setopt($curlObj, CURLOPT_USERPWD, &#8220;$username:$password&#8221;);<br />
curl_setopt($curlObj, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);<br />
$output = curl_exec($curlObj);<br />
$transferInfo = curl_getinfo($curlObj);<br />
curl_close($curlObj);<br />
print_r( $transferInfo );<br />
?&gt;</p></blockquote>
<p><strong>Note:</strong> Replace the following variables in the above code</p>
<p>- {chosen username}</p>
<p>- {chosen encrypted password}</p>
<p>- {Project Name}</p>
<p>- {PHP File}</p>
<p>The line curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true); enables to retrieve the data in a variable from a remote file.</p>
<p>Thus in this way, you are able to successfully access a remote file using cURL.</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2011/01/29/access-file-in-restricted-folder-in-php-with-curl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPUnit on Windows with WAMP and Netbeans</title>
		<link>http://ushainformatique.com/blog/2011/01/29/phpunit-on-windows-with-wamp-and-netbeans/</link>
		<comments>http://ushainformatique.com/blog/2011/01/29/phpunit-on-windows-with-wamp-and-netbeans/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 12:08:57 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Unit Test]]></category>
		<category><![CDATA[PHPUnit]]></category>
		<category><![CDATA[PHPUnit in Netbeans]]></category>
		<category><![CDATA[PHPUnit on Windows with WAMP]]></category>
		<category><![CDATA[PHPUnit with Wamp and Netbeans]]></category>
		<category><![CDATA[Setup PHPUnit on Windows]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=78</guid>
		<description><![CDATA[In any software development project, the key to success is the creation of unit test cases and thorough usage of them during development and post development.
On the same line of Java, which provides JUnit as the Unit Testing Framework, PHPUnit can be used. I have gone through many resources on Internet and collated the information [...]]]></description>
			<content:encoded><![CDATA[<p>In any software development project, the key to success is the creation of unit test cases and thorough usage of them during development and post development.</p>
<p>On the same line of Java, which provides JUnit as the Unit Testing Framework, PHPUnit can be used. I have gone through many resources on Internet and collated the information in this blog.</p>
<p><em><strong>Steps</strong><strong> to follow</strong></em></p>
<p>- On successful installation of WAMP, open up the command prompt and go to your php directory in WAMP</p>
<p>- D:\&gt;cd wamp\bin\php\php5.2.5</p>
<p><span style="text-decoration: underline;"><em><strong>Pear Set Up</strong></em></span></p>
<p>- Execute go-pear.bat file to install PEAR</p>
<p>- Accept the defaults for the questions asked by PEAR</p>
<p>- On installation of PEAR,  run PEAR_ENV.reg. It would create the environment variables to make pear globally available in command line</p>
<p>- D:\wamp\bin\php\php5.2.5&gt;PEAR_ENV.reg</p>
<p><span style="text-decoration: underline;"><em><strong>Register PHPUnit with PEAR</strong></em></span></p>
<p>- Once you have PEAR setup, then you must register the PHPUnit channel with PEAR</p>
<p>- D:\wamp\bin\php\php5.2.5&gt;pear upgrade pear</p>
<p>- D:\wamp\bin\php\php5.2.5&gt;<span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">pear install </span><span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">&#8211;</span><span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">alldeps </span><span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">&#8211;</span><span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">force phpunit</span><span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">/</span><span style="vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; padding: 0px; margin: 0px; border: 0px initial initial;">phpunit</span></p>
<p>- You should now find the PHPUnit source files under the PHP directory with phpunit.bat in php main folder</p>
<p>- Restart wamp</p>
<p><span style="text-decoration: underline;"><em><strong>XDebug Set Up</strong></em></span></p>
<p>- Netbeans version should be 6.8 ( It will not work with version 6.5 )</p>
<p>- Install xdebug using the guidelines from http://xdebug.org/download.php and http://xdebug.org/install.php</p>
<p>- In php.ini ( Apache one ) copy the following lines</p>
<p>a. 	zend_extension_ts = &#8220;D:/wamp/bin/php/php5.2.9-1/ext/php_xdebug-2.1.0-5.2-vc6.dll&#8221;<br />
b. 	xdebug.remote_enable=on<br />
c. 	xdebug.remote_handler=dbgp<br />
d. 	xdebug.remote_host=localhost<br />
e. 	xdebug.remote_port=9000</p>
<p>- Restart wamp</p>
<p>- Go to Tools-&gt;Options-&gt;PHP-&gt;general tab</p>
<p>- In general tab there is debugging option: Debugging port:=9000 session ID= netbean xdebug</p>
<p>- Remove net beans and write session ID = xdebug</p>
<p>- Restart IDE.</p>
<p>- Right click on file in the project and go to Tool-&gt;create PHPUnit tests . It will ask select the directory with project test file.  Create a folder let’s say called “tests” in the project</p>
<p>- Test files would be created inside the folder</p>
<p>- For e.g. if we are writing test case for search.php, searchtest.php in the test folder would be created.</p>
<p>- Right click on the project folder and click on Test which would run all the test cases in the project against all the classes</p>
<p>- Also you can run the code completion by right clicking on the project folder and select code completion which would show you the results as how many functions in the project are there with test cases written for them.</p>
<p>You are all set to test your PHP classes with PHPUnit with debugging enabled.</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2011/01/29/phpunit-on-windows-with-wamp-and-netbeans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EJB 3.1 Application with Stateless Session Bean on Glassfish 3.0 and NetBeans</title>
		<link>http://ushainformatique.com/blog/2010/06/18/ejb-3-1-application-with-stateless-session-bean-on-glassfish-3-0-and-netbeans/</link>
		<comments>http://ushainformatique.com/blog/2010/06/18/ejb-3-1-application-with-stateless-session-bean-on-glassfish-3-0-and-netbeans/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 05:51:17 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[EJB]]></category>
		<category><![CDATA[@EJB annotation in EJB application]]></category>
		<category><![CDATA[EJB 3.0 application with a Servlet]]></category>
		<category><![CDATA[EJB 3.0 Application with Stateless Session Bean]]></category>
		<category><![CDATA[Sample EJB 3.0 application]]></category>
		<category><![CDATA[Sample EJB 3.0 application in Netbeans]]></category>
		<category><![CDATA[Sample EJB 3.0 application with Glassfish]]></category>
		<category><![CDATA[Sample EJB application in glassfish]]></category>
		<category><![CDATA[Sample EJB application in Netbeans]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=72</guid>
		<description><![CDATA[Enterprise Java Beans (EJB) is a bit complex topic before the release of EJB 3.0 specification. In the EJB 3.0 specification the things are much simplified now from many perspectives
- Development of application using EJB
- Maintaining application having EJB
- Understanding of EJB for a new beginner
We have developed a sample application (with both local and [...]]]></description>
			<content:encoded><![CDATA[<p>Enterprise Java Beans (EJB) is a bit complex topic before the release of EJB 3.0 specification. In the EJB 3.0 specification the things are much simplified now from many perspectives</p>
<p>- Development of application using EJB</p>
<p>- Maintaining application having EJB</p>
<p>- Understanding of EJB for a new beginner</p>
<p>We have developed a sample application (with both local and remote interface) which illustrates creation of EJB and using it in a servlet. The infrastructure parts of the application are as follows</p>
<p>- NetBeans 6.8</p>
<p>- Glassfish Application Server (v 3.0)</p>
<p>The steps that needs to be followed are as follows</p>
<p>- Create a New Java EE Project SampleEJBApplication in Netbeans. Just follow the instruction provided by Netbeans.</p>
<p>- There would be three folders created ( SampleEJBApplication, SampleEJBApplication-ejb, SampleEJBApplication-war )</p>
<p><em><strong><u>EJB Application</u></strong></em></p>
<p>- In the <strong>SampleEJBApplication-ejb</strong>, create a package called com.sample.service</p>
<p>- Create a Local Interface called Calculator.java as follows</p>
<blockquote><p>package com.sample.service;</p>
<p>import javax.ejb.Local;</p>
<p>/**<br />
*<br />
* @author Shashank<br />
*/<br />
@Local<br />
public interface Calculator<br />
{</p>
<p>public int calculate (int start, int end);</p>
<p>}</p></blockquote>
<p>- Look out for @Local annotation which declare the interface to be local</p>
<p>- Create a class called CalculatorBean.java as follows which implements the local interface</p>
<blockquote><p>package com.sample.service;</p>
<p>import javax.ejb.EJB;<br />
import javax.ejb.Local;<br />
import javax.ejb.Remote;<br />
import javax.ejb.Stateless;</p>
<p>/**<br />
*<br />
* @author Shashank<br />
*/<br />
@Stateless</p>
<p>@EJB(name=&#8221;java:global/MyCalculatorBean&#8221;, beanInterface=Calculator.class)<br />
public class CalculatorBean implements Calculator {</p>
<p>public String getServerInfo () {<br />
return &#8220;This is glass fish server using EE6 version&#8221;;<br />
}</p>
<p>public int calculate(int start, int end) {<br />
return start+end;</p>
<p>}</p>
<p>public int remoteCalculate(int start, int end) {<br />
return start+end;<br />
}</p>
<p>}</p></blockquote>
<p>Notice few things in the above class</p>
<p>- @Stateless annotation which declares the bean to be stateless</p>
<p>- @EJB(name=&#8221;java:global/MyCalculatorBean&#8221;,  beanInterface=Calculator.class), it says that when referring to this bean using JNDI it could be called using  java:global/MyCalculatorBean</p>
<p><em><strong><u>Front End Application (SampleEJBApplication-war)</u></strong></em></p>
<p>- Inside the Source folder, create a package called servlets</p>
<p>- Now there are <strong>two approach using which you can refer to local EJB</strong></p>
<p><em><u>Approach 1</u></em></p>
<p>- Use @EJB annotation inside the servlet to call the local EJB ( Available with Glassfish and not JBoss <img src='http://ushainformatique.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</p>
<p><em><u>Approach 2</u></em></p>
<p>- Use JNDI lookup inside the servlet to call the local EJB</p>
<p>- Create a servlet called TestServlet.java using Netbeans</p>
<p>- For <strong>Approach 1</strong> the code will go as follows</p>
<blockquote><p><em>protected void processRequest(HttpServletRequest request, HttpServletResponse response)<br />
throws ServletException, IOException {<br />
response.setContentType(&#8221;text/html;charset=UTF-8&#8243;);<br />
PrintWriter out = response.getWriter();</em></p>
<p><em>Calculator calculatorBean;<br />
try {</em></p>
<p><em>Context context = new InitialContext();<br />
calculatorBean = (Calculator) context.lookup(&#8221;java:global/MyCalculatorBean&#8221;);<br />
out.println(&#8221;&lt;html&gt;&#8221;);<br />
out.println(&#8221;&lt;head&gt;&#8221;);<br />
out.println(&#8221;&lt;title&gt;Servlet TestServlet&lt;/title&gt;&#8221;);<br />
out.println(&#8221;&lt;/head&gt;&#8221;);<br />
out.println(&#8221;&lt;body&gt;&#8221;);<br />
out.println(&#8221;&lt;h1&gt;Servlet TestServlet at &#8221; + request.getContextPath() + &#8220;&lt;/h1&gt;&#8221;);<br />
out.println(calculatorBean.calculate(100, 200));<br />
out.println(&#8221;&lt;/body&gt;&#8221;);<br />
out.println(&#8221;&lt;/html&gt;&#8221;);</em></p>
<p><em>} catch (NamingException nex) {<br />
nex.printStackTrace();<br />
} finally {<br />
out.close();<br />
}<br />
}</em></p></blockquote>
<p>- Please notice as how the bean is referred using the JNDI name defined in bean class</p>
<p>- The same bean can be retrieved by using</p>
<p>a) (Calculator) context.lookup(&#8221;com.sample.service.Calculator&#8221;) (<strong>Non Portable JNDI lookup</strong>)</p>
<p>b) java:global/SampleEJBApplication/SampleEJBApplication-ejb/CalculatorBean!com.sample.service.Calculator (<strong>Portable JNDI lookup</strong>)</p>
<p>- For Approach 2, the code would go as follows</p>
<blockquote><p><em>@EJB<br />
private Calculator calculatorBean;<br />
/**<br />
* Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt; methods.<br />
* @param request servlet request<br />
* @param response servlet response<br />
* @throws ServletException if a servlet-specific error occurs<br />
* @throws IOException if an I/O error occurs<br />
*/<br />
protected void processRequest(HttpServletRequest request, HttpServletResponse response)<br />
throws ServletException, IOException {<br />
response.setContentType(&#8221;text/html;charset=UTF-8&#8243;);<br />
PrintWriter out = response.getWriter();</em></p>
<p><em>try {</em></p>
<p><em>out.println(&#8221;&lt;html&gt;&#8221;);</em> <em><br />
out.println(&#8221;&lt;head&gt;&#8221;);<br />
out.println(&#8221;&lt;title&gt;Servlet TestServlet&lt;/title&gt;&#8221;);<br />
out.println(&#8221;&lt;/head&gt;&#8221;);<br />
out.println(&#8221;&lt;body&gt;&#8221;);<br />
out.println(&#8221;&lt;h1&gt;Servlet TestServlet at &#8221; + request.getContextPath () + &#8220;&lt;/h1&gt;&#8221;);<br />
out.println(calculatorBean.calculate(100, 200));<br />
out.println(&#8221;&lt;/body&gt;&#8221;);<br />
out.println(&#8221;&lt;/html&gt;&#8221;);</em></p>
<p><em>} finally { </em> <em><br />
out.close();<br />
}<br />
}</em></p></blockquote>
<p><em>- </em>Notice the usage of @EJB annotation with no issues regarding JNDI</p>
<p>- Run the code in both cases and should return 300 as the result</p>
<p>The implemtation for the remote interface would be given in next post.</p>
<p>Enjoy EJB 3.0 !!</p>
<p><strong><em>Ushainformatique Development Team</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/06/18/ejb-3-1-application-with-stateless-session-bean-on-glassfish-3-0-and-netbeans/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Usage of Data Access Object (DAO) pattern in PHP</title>
		<link>http://ushainformatique.com/blog/2010/05/31/usage-of-data-access-object-dao-pattern-in-php/</link>
		<comments>http://ushainformatique.com/blog/2010/05/31/usage-of-data-access-object-dao-pattern-in-php/#comments</comments>
		<pubDate>Mon, 31 May 2010 11:52:45 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[Data Access Object]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DAO Pattern in PHP]]></category>
		<category><![CDATA[Data Access Object Pattern in PHP]]></category>
		<category><![CDATA[Usage of DAO pattern in PHP]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=57</guid>
		<description><![CDATA[Data Access Object pattern is a heavily used design pattern used in J2EE, but good thing is that it could be used in a very efficient manner in PHP.
What is DAO pattern?
The very first thing we need to understand is what is DAO pattern. In our last blog on DTO, it is emphasized that Data [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Data Access Object pattern</strong> is a heavily used design pattern used in J2EE, but good thing is that it could be used in a very efficient manner in PHP.<em><strong></strong></em></p>
<p><strong><span style="text-decoration: underline;">What is DAO pattern?</span></strong></p>
<p>The very first thing we need to understand is what is DAO pattern. In our last blog on DTO, it is emphasized that Data Object is an exact replica of a database table with getter and setter methods for the fields.</p>
<p>Let&#8217;s assume that a database connection is created in the controller or in the managed bean of JSF and dataobject is populated with the results. Now i need to execute the same query in another controller or managed bean than i need to again write the same query. Thus in this way our database layer is tightly coupled to the web part.</p>
<p>Thus to abstract the database layer, if a new layer is introduced in between web and database which provides an interface to access the database, it would decouple the database from the web layer. Also, the same query hasn&#8217;t need to be rewritten. This is what is called Data Access Object Layer.</p>
<p><strong><span style="text-decoration: underline;">Usage of DAO pattern</span></strong></p>
<p><em><strong><span style="text-decoration: underline;">Option 1</span></strong></em><br />
- Create a class called EmployerDAO.php</p>
<p>- Let&#8217;s say i want to display the list of employers, than my function would go like in the EmployerDAO.php</p>
<blockquote><p>public function getEmployerDetails($id)<br />
{<br />
$employerQuery = &#8220;select * from tbl_employer where employerid=&#8217;$id&#8217;&#8221;;<br />
$tempEmployerVO = new EmployerVO();</p>
<p>$employerResult = mysql_query($employerQuery);<br />
$row = mysql_fetch_array($employerResult) ;</p>
<p>$tempEmployerVO-&gt; setId() = $row-&gt; id;</p>
<p>$tempEmployerVO-&gt;  setFirstname() = $row-&gt;firstname;</p>
<p>$tempEmployerVO-&gt; setLastname() = $row-&gt;lastname;</p>
<p>return $tempEmployerVO;<br />
}</p></blockquote>
<p>Thus in the controller, you would instantiate the DAO class and call this method to retrieve the dataobject of employer.</p>
<p>In this way wherever you want to have the enployer details, just instantiate the DAO and call the result.</p>
<p><em>The key point to note here is that if the same table is used in another php project, you can use the same DAO layer. Thus it improves the efficiency and maintenance of the code to a large extent.</em></p>
<p><em><strong><span style="text-decoration: underline;">Option 2</span></strong></em></p>
<p>Another way you can use the same DAO layer is as the interface and different classes can implement the interface as per the requirement. This is one more level of abstraction.</p>
<p>It would be helpful in cases where you have different logic to be implemented before populating the dataobject.</p>
<p>Give it a try !!</p>
<p>Ushainformatique Development Team</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/05/31/usage-of-data-access-object-dao-pattern-in-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dynamic JSF application with MySQL on Glassfish with Toplink</title>
		<link>http://ushainformatique.com/blog/2010/05/08/dynamic-jsf-application-with-mysql-on-glassfish-with-toplink/</link>
		<comments>http://ushainformatique.com/blog/2010/05/08/dynamic-jsf-application-with-mysql-on-glassfish-with-toplink/#comments</comments>
		<pubDate>Sat, 08 May 2010 09:56:46 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[JDBC]]></category>
		<category><![CDATA[Java Persistence]]></category>
		<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[JSF Application in Netbeans with Persistence]]></category>
		<category><![CDATA[JSF application with JPA]]></category>
		<category><![CDATA[JSF application with Persistence]]></category>
		<category><![CDATA[JSF application with Toplink JPA]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=42</guid>
		<description><![CDATA[In my last post, i talked about developing a Dynamic JSF application with MySQL on JBoss with simple JDBC connection.
In this post, i am going to talk about a sample application with
- JSF
- Netbeans 6.8
- Glassfish Application Server
- MySQL Database
- Persistence API (Provider Toplink)

About the application
This would be a simple application which performs the following
- [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, i talked about developing a Dynamic JSF application with MySQL on JBoss with simple JDBC connection.</p>
<p>In this post, i am going to talk about a sample application with</p>
<p>- JSF</p>
<p>- Netbeans 6.8</p>
<p>- Glassfish Application Server</p>
<p>- MySQL Database</p>
<p>- <strong>Persistence API (Provider Toplink)<br />
</strong></p>
<p><strong><em><span style="text-decoration: underline;">About the application</span></em></strong></p>
<p>This would be a simple application which performs the following</p>
<p>- Insert Person Data into the database</p>
<p>- Fetch the person list from the database</p>
<blockquote><p><strong>The key difference over here is that we are going to use Java Persistence API over here to make the transactions.</strong></p></blockquote>
<p>First of all we need to understand as <strong>what is Java Persistence API</strong>.  As per the sun here is a very good definition for JPA.</p>
<blockquote><p><em>The Java Persistence API is a POJO persistence API for object/relational mapping.  It contains a full object/relational mapping specification supporting the use of Java language metadata annotations and/or XML descriptors to define the mapping between Java objects and a relational database.  It supports a rich, SQL-like query language (which is a significant extension upon EJB QL) for both static and dynamic queries.  It also supports the use of pluggable persistence providers.</em></p></blockquote>
<p>Thus with the evolution of Java Persistence API, a standard of persistence framework has been set and many vendors are providing the implementation of the API and toplink is the open-source community edition of Oracle&#8217;s TopLink product.</p>
<p><em><strong><span style="text-decoration: underline;">Implementation</span></strong></em></p>
<p>- In Netbeans, Create a Java Web project called TestPersonApplication and select the JSF framework while creating it. The folder structure would be created.</p>
<p>- After that create a mysql database,  in my case i call it jsfperson with table as person. The person table would have <strong>id (int), firstname (varchar) and lastname</strong> <strong>(varchar)</strong> as the fields</p>
<p>- Run the Glassfish Application Server and from services tab, against the server click &#8220;<strong><em>View Admin Console</em></strong>&#8221;</p>
<p><em><strong><span style="text-decoration: underline;">Connection Pool Creation and JDBC resource creation</span></strong></em></p>
<p>- After the admin console is loaded, click on JDBC and JDBC resources would be displayed</p>
<p>- Under <strong>Connection Pool</strong>, Click on Add a New Pool</p>
<p>- Enter Name, Resource Type as javax.sql.Datasource and Vendor as MySql and click on Next</p>
<p>- On the next screen, add the properties User, portnumber (3306), databaseName (jsfperson), Password, driverClass (com.mysql.jdbc.Driver), URL (jdbc:mysql://localhost:3306/jsfperson) and serverName(localhost) and click on Finish</p>
<p>- After Finish, click on Ping to check the connection, if the ping is successfully, your pool is created perfectly</p>
<p>- Now under <strong>JDBC resources</strong>, Click on &#8220;New&#8221;</p>
<p>- Enter the JNDI name and select the pool you created above (By default, when you again run the server, it creates a pool like mysql_jsfperson_rootPool, check that <img src='http://ushainformatique.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ) and click on Save</p>
<p>- After the save check <em><strong>sun-resources.xml under Server Resources</strong> </em>and you will see the configuration</p>
<p><em><strong><span style="text-decoration: underline;">Creation of Entity Class</span></strong></em></p>
<p>- Coming to Netbeans again, under Source Packages folder, create a package called com.domain</p>
<p>- Right click on the folder and select New &#8211; &gt;Entity class from Database</p>
<p>- Select the datasource as jsfperson (Which you added earlier) and it will retrieve the database schema</p>
<p>- Select the table and Click on Add and than click on Next</p>
<p>- On next screen, it would show you the details for Person Entity and click on Finish</p>
<p>- The object would be created with Annotations for the mapping between Entity fields and Database field. The generated code would go like this</p>
<blockquote><p><em>@Id<br />
@Basic(optional = false)<br />
@Column(name = &#8220;id&#8221;)<br />
private Integer id;<br />
@Column(name = &#8220;firstname&#8221;)<br />
private String firstname;<br />
@Column(name = &#8220;lastname&#8221;)<br />
private String lastname;</em></p></blockquote>
<p>The class would implement Serializable interface with getter, setter methods for the fields, equals method and toString Method. In addition, the queries would be generated as follows</p>
<blockquote><p>@Entity<br />
@Table(name = &#8220;person&#8221;)<br />
@NamedQueries({<br />
@NamedQuery(name = &#8220;Person.findAll&#8221;, query = &#8220;SELECT p FROM Person p&#8221;),<br />
@NamedQuery(name = &#8220;Person.findById&#8221;, query = &#8220;SELECT p FROM Person p WHERE p.id = :id&#8221;),<br />
@NamedQuery(name = &#8220;Person.findByFirstname&#8221;, query = &#8220;SELECT p FROM Person p WHERE p.firstname = :firstname&#8221;),<br />
@NamedQuery(name = &#8220;Person.findByLastname&#8221;, query = &#8220;SELECT p FROM Person p WHERE p.lastname = :lastname&#8221;)<br />
})</p></blockquote>
<p>Check the <strong>@Entity and @Table</strong> annotation (Here the mapping starts) !!</p>
<p><em><strong><span style="text-decoration: underline;">Creation of Persistence Unit</span></strong></em></p>
<p>- Right click on the project and select New -&gt; Other -&gt; Persistence -&gt;Persistence Unit</p>
<p>- Enter Name, persistence provider which is Toplink and datasource created (jsfperson)</p>
<p>- Click on Finish and a file called persistence.xml would be created under configuration with transaction type as JTA</p>
<p>- Enter the class for which this PU would be used.  The xml would go like</p>
<blockquote><p>&lt;?xml version=&#8221;1.0&#8243; encoding=&#8221;UTF-8&#8243;?&gt;<br />
&lt;persistence version=&#8221;1.0&#8243; xmlns=&#8221;http://java.sun.com/xml/ns/persistence&#8221; xmlns:xsi=&#8221;http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:schemaLocation=&#8221;http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&#8221;&gt;<br />
&lt;persistence-unit name=&#8221;TestJSFApplicationPU&#8221; transaction-type=&#8221;JTA&#8221;&gt;<br />
&lt;provider&gt;oracle.toplink.essentials.PersistenceProvider&lt;/provider&gt;<br />
&lt;jta-data-source&gt;jsfperson&lt;/jta-data-source&gt;<br />
&lt;class&gt;com.domain.Person&lt;/class&gt;<br />
&lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;<br />
&lt;properties/&gt;<br />
&lt;/persistence-unit&gt;</p>
<p>&lt;/persistence&gt;</p></blockquote>
<p><em><strong><span style="text-decoration: underline;">Creation of JSF Managed Bean</span></strong></em></p>
<p>- Create a folder called com.testjsf under Sources Folder</p>
<p>- Right click on it and select New Jsf Managed Bean called PersonBean with configuration file as <strong>faces-config.xml</strong> under WEB-INF</p>
<p>- Declare two variables named Person (Entity Object ) and personList</p>
<p>- Create the getter and setter method for the variables</p>
<p><em><strong><span style="text-decoration: underline;">Creation of Data Access Object</span></strong></em></p>
<p>Now we will make the connection class using <strong>DAO (data access object) design pattern</strong></p>
<p>- Create a package called com.dao and create a class called PersonDAO</p>
<p>- The class would look like the following</p>
<blockquote><p>/*<br />
* To change this template, choose Tools | Templates<br />
* and open the template in the editor.<br />
*/<br />
package com.dao;</p>
<p>import com.domain.Person;<br />
import java.util.ArrayList;<br />
import java.util.List;<br />
import javax.persistence.EntityManager;<br />
import javax.persistence.EntityManagerFactory;<br />
import javax.persistence.Persistence;<br />
import javax.persistence.Query;</p>
<p>/**<br />
*<br />
* @author Shashank<br />
*/<br />
public class PersonDAO {</p>
<p>public void insertData(Person p){</p>
<p>EntityManagerFactory emf = Persistence.createEntityManagerFactory(&#8221;TestJSFApplicationPU&#8221;);<br />
EntityManager em= emf.createEntityManager();</p>
<p>try<br />
{<br />
em.getTransaction().begin();<br />
em.persist(p);<br />
em.getTransaction().commit();<br />
}<br />
catch(Exception e)<br />
{<br />
e.printStackTrace();<br />
}<br />
finally<br />
{<br />
em.close();<br />
}<br />
}</p>
<p>public List getPersonList() {<br />
List empList=null;<br />
EntityManagerFactory emf = Persistence.createEntityManagerFactory(&#8221;TestJSFApplicationPU&#8221;);<br />
EntityManager em= emf.createEntityManager();</p>
<p>try<br />
{<br />
Query q= em.createNamedQuery(&#8221;Person.findAll&#8221;);<br />
empList= q.getResultList();<br />
}<br />
catch(Exception e)<br />
{<br />
e.printStackTrace();<br />
}<br />
finally<br />
{<br />
em.close();<br />
}<br />
return empList;<br />
}<br />
}</p></blockquote>
<p>In the above class there are few things to note</p>
<p>- JPA provides a class called EntityManagerFactory identified by persistence unit created above which manages all the transaction handling</p>
<p>- For example, to insert the data assuming Person object is there</p>
<p>a) Create a EntityManagerFactory</p>
<p>b) Create a Entity Manager</p>
<p>c) Begin transaction with em.getTransaction().begin()</p>
<p>d) call the persist function with person object as the argument. This statement would insert the data into the database</p>
<p>e) Finally commit is called</p>
<p>After creating the class, come back to PersonBean class and in the constructor for it, instantiate Person and Personlist (by calling PersonDAO getPersonList method). The constructor would go like</p>
<blockquote><p>public PersonBean() {<br />
person= new Person();</p>
<p>PersonDAO pDao= new PersonDAO();<br />
personList = pDao.getPersonList();<br />
}</p></blockquote>
<p>Add two methods to it for adding a person and listing all persons which are as follows</p>
<blockquote><p>public String addPerson()<br />
{<br />
PersonDAO pDao= new PersonDAO();<br />
pDao.insertData(this.person);<br />
this.setPersonList(pDao.getPersonList());<br />
return &#8220;<strong>greeting</strong>&#8220;;<br />
}</p>
<p>public String getAllPersonList()<br />
{<br />
PersonDAO pDao= new PersonDAO();<br />
this.setPersonList(pDao.getPersonList());</p>
<p>return &#8220;<strong>go_person_list</strong>&#8220;;<br />
}</p></blockquote>
<p>Ok, now you are done with back end part. Keep the last two return statement in mind. I would discuss about them in the post below.</p>
<p><em><strong><span style="text-decoration: underline;">Front End with JSF</span></strong></em></p>
<p>In the front end, add a file addPerson.jsp with firstname and lastname. The JSF part of it would go like</p>
<blockquote><p>&lt;f:view&gt;<br />
&lt;h1&gt;<br />
&lt;h:outputText value=&#8221;#{msg.inputname_header}&#8221;/&gt;<br />
&lt;/h1&gt;<br />
&lt;h:form id=&#8221;helloForm&#8221;&gt;<br />
&lt;h:outputText value=&#8221;#{msg.prompt}&#8221;/&gt;<br />
&lt;h:inputText value=&#8221;#{<strong>personBean.person.firstname</strong>}&#8221; /&gt;<br />
&lt;h:inputText value=&#8221;#{<strong>personBean.person.lastname</strong>}&#8221; /&gt;<br />
&lt;h:commandButton action=&#8221;#{<strong>personBean.addPerson</strong>}&#8221; value=&#8221;#{msg.button_text}&#8221; /&gt;<br />
&lt;h:commandLink action=&#8221;<strong>go_person_list</strong>&#8221; value=&#8221;Show all persons&#8221;/&gt;<br />
&lt;/h:form&gt;<br />
&lt;/f:view&gt;</p></blockquote>
<p>Note that against the <strong>button action is mapped to addPerson method in the bean class</strong>.  The &#8220;h&#8221; and &#8220;f&#8221; tags are html and core tag libraries for JSF.</p>
<p><em><strong><span style="text-decoration: underline;">faces-config.xml</span></strong></em></p>
<p>- Person bean is already added</p>
<p>- Add person as the managed property for it as</p>
<blockquote><p>&lt;managed-bean&gt;<br />
&lt;managed-bean-name&gt;personBean&lt;/managed-bean-name&gt;<br />
&lt;managed-bean-class&gt;com.testjsf.PersonBean&lt;/managed-bean-class&gt;<br />
&lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;<br />
&lt;managed-property&gt;<br />
&lt;property-name&gt;person&lt;/property-name&gt;<br />
&lt;property-class&gt;com.domain.Person&lt;/property-class&gt;<br />
&lt;value&gt;#{person}&lt;/value&gt;<br />
&lt;/managed-property&gt;<br />
&lt;/managed-bean&gt;</p></blockquote>
<p>This is how the person object is accessed under personbean in the jsf.</p>
<p><em><strong><span style="text-decoration: underline;">Handling Navigation</span></strong></em></p>
<p>- Add the navigation rule as follows</p>
<blockquote><p>&lt;navigation-rule&gt;<br />
&lt;from-view-id&gt;/welcomeJSF.jsp&lt;/from-view-id&gt;<br />
&lt;navigation-case&gt;<br />
&lt;from-outcome&gt;greeting&lt;/from-outcome&gt;<br />
&lt;to-view-id&gt;/personlist.jsp&lt;/to-view-id&gt;<br />
&lt;/navigation-case&gt;<br />
&lt;from-view-id&gt;/welcomeJSF.jsp&lt;/from-view-id&gt;<br />
&lt;navigation-case&gt;<br />
&lt;from-outcome&gt;go_person_list&lt;/from-outcome&gt;<br />
&lt;to-view-id&gt;/personlist.jsp&lt;/to-view-id&gt;<br />
&lt;/navigation-case&gt;<br />
&lt;/navigation-rule&gt;</p></blockquote>
<p>- On submission of form, addMethod is called. If you see the last statement given above, on return &#8220;<strong>greeting&#8221;</strong> , the flow would go to first navigation rule with from view as welcomeJSF.jsp and action as greeting thus personlist.jsp would be called and loaded.</p>
<p>- The person list file would go like</p>
<blockquote><p>&lt;f:view&gt;<br />
&lt;h:form&gt;<br />
&lt;h:dataTable value=&#8221;#<strong>{personBean.personList}</strong>&#8221; var=&#8221;item&#8221;&gt;<br />
&lt;h:column&gt;<br />
&lt;f:facet name=&#8221;header&#8221;&gt;<br />
&lt;h:outputText value=&#8221;Id&#8221;/&gt;<br />
&lt;/f:facet&gt;<br />
&lt;h:outputText value=&#8221;#{item.id}&#8221;/&gt;<br />
&lt;/h:column&gt;<br />
&lt;h:column&gt;<br />
&lt;f:facet name=&#8221;header&#8221; &gt;<br />
&lt;h:outputText value=&#8221;First Name&#8221;/&gt;<br />
&lt;/f:facet&gt;<br />
&lt;h:outputText value=&#8221;#{item.firstname}&#8221;/&gt;<br />
&lt;/h:column&gt;<br />
&lt;h:column&gt;<br />
&lt;f:facet name=&#8221;header&#8221; &gt;<br />
&lt;h:outputText value=&#8221;Last Name&#8221;/&gt;<br />
&lt;/f:facet&gt;<br />
&lt;h:outputText value=&#8221;#{item.lastname}&#8221;/&gt;<br />
&lt;/h:column&gt;</p>
<p>&lt;/h:dataTable&gt;<br />
&lt;/h:form&gt;<br />
&lt;/f:view&gt;</p></blockquote>
<p>In the file above, <em>when {personBean.personList} is called, personBean is invoked and in the constructor, the latest person list is set. Thus on calling getter for personList, it returns the latest list after addition.</em></p>
<p>Thus you can develop the sample application using JPA with JSF in netbeans.</p>
<p>Thanks,</p>
<p>Ushainformatique Development Team</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/05/08/dynamic-jsf-application-with-mysql-on-glassfish-with-toplink/feed/</wfw:commentRss>
		<slash:comments>68</slash:comments>
		</item>
		<item>
		<title>Implement Yahoo weather API along with Google map integration</title>
		<link>http://ushainformatique.com/blog/2010/05/02/implement-yahoo-weather-on-your-site-along-with-google-map/</link>
		<comments>http://ushainformatique.com/blog/2010/05/02/implement-yahoo-weather-on-your-site-along-with-google-map/#comments</comments>
		<pubDate>Sun, 02 May 2010 18:23:17 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[API]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Yahoo]]></category>
		<category><![CDATA[Google Map integration]]></category>
		<category><![CDATA[Yahoo weather API implementation]]></category>
		<category><![CDATA[Yahoo weather API integration]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=35</guid>
		<description><![CDATA[Requirements
We got a requirement to display weather for a city along with google map for the city.
Approach
There can be two approach that can be used
1) Implement yahoo weather API and Google map separately thus each is working independently
2) Implement google map using the information derived from yahoo weather API
Here i am going to talk about [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>Requirements</strong></em></p>
<p>We got a requirement to display weather for a city along with google map for the city.</p>
<p><em><strong>Approach</strong></em></p>
<p>There can be two approach that can be used</p>
<p>1) Implement yahoo weather API and Google map separately thus each is working independently</p>
<p>2) Implement google map using the information derived from yahoo weather API</p>
<p>Here i am going to talk about the <strong>second approach</strong></p>
<p>To access weather for any city using Yahoo weather API, you have to use the following code</p>
<blockquote><p>&lt;?php</p>
<p>&lt;span&gt;XML&lt;/span&gt; document into memory first.</p>
<p>$doc = new DOMDocument();</p>
<p>$doc-&gt;load(&#8217;<strong>http://weather.yahooapis.com/forecastrss?w=&#8217;.$weatherlocation.&#8217;&amp;u=c</strong>&#8216;);</p>
<p>//now I get all elements inside this document with the following name &#8220;channel&#8221;, this is the &#8216;root&#8217;</p>
<p>$channel = $doc-&gt;getElementsByTagName(&#8221;channel&#8221;);</p>
<p>//now I go through each item withing $channel</p>
<p>foreach($channel as $chnl)<br />
{</p>
<p>$item = $chnl-&gt;getElementsByTagName(&#8221;item&#8221;);</p>
<p>foreach($item as $itemgotten)<br />
{</p>
<p>echo &#8220;&lt;b&gt;&#8221;.$itemgotten-&gt;getElementsByTagName(&#8221;title&#8221;)-&gt;item(0)-&gt;nodeValue.&#8221;&lt;/b&gt;&lt;br/&gt;&#8221;;</p>
<p>//now I search within &#8216;$item&#8217; for the element &#8220;description&#8221;</p>
<p>$describe = $itemgotten-&gt;getElementsByTagName(&#8221;description&#8221;);</p>
<p>//once I find it I create a variable named &#8220;$description&#8221; and assign the value of the Element to it</p>
<p>$description = $describe-&gt;item(0)-&gt;nodeValue;</p>
<p>//and display it on-screen</p>
<p>echo $description;</p>
<p><em>$latitude=$itemgotten-&gt;getElementsByTagName(&#8221;lat&#8221;)-&gt;item(0)-&gt;nodeValue;<br />
</em></p>
<p><em>$longitude=$itemgotten-&gt;getElementsByTagName(&#8221;long&#8221;)-&gt;item(0)-&gt;nodeValue;<br />
</em></p>
<p>}</p>
<p>}<br />
?&gt;</p></blockquote>
<p>In the above code, the yahoo weather url is called with arguments w and u (Unit of temperature). &#8220;w&#8221; is the location of the city you want the get the weather for. This you will get from yahoo weather page http://weather.yahoo.com.</p>
<p>Simply enter the city and from the url retrieve the value for e.g in http://weather.yahoo.com/united-states/california/bombay-2366506/, 2366506 is the value of &#8220;w&#8221;.</p>
<p><strong>The last two lines</strong> in the code above are the tricky one&#8217;s. From the last two lines, you can retrieve the <strong>latitude and longitude of the place</strong>, thus think you are saving so much database space by not storing latitude and longitude of places.</p>
<p>After getting the latitude and longitude for the place just pass to it google map API code which in my case is like the following</p>
<blockquote><p>&lt;script type=&#8221;text/javascript&#8221; src=&#8221;http://www.google.com/jsapi?key=ABQIAAAAQg2VLDfgi8yxVrFlqjXF7xTQHiNlpCS1vy260As8BGMS2rl5kBTvFuKiyHlh1z2mfCbd6sJqj9WfIw&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
google.load(&#8221;maps&#8221;, &#8220;2.x&#8221;);<br />
&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; charset=&#8221;utf-8&#8243;&gt;<br />
$(document).ready(function(){<br />
var map = new GMap2($(&#8221;#mapdiv&#8221;).get(0));</p>
<p>var delhi = new GLatLng(&lt;?php echo $latitude; ?&gt;,&lt;?php echo $longitude; ?&gt;);<br />
map.setCenter(delhi,8);<br />
marker = new GMarker(delhi);<br />
map.addOverlay(marker);<br />
});<br />
&lt;/script&gt;<br />
&lt;style type=&#8221;text/css&#8221; media=&#8221;screen&#8221;&gt;<br />
#mapdiv { float:left; width:213px; height:144px;padding:0px 0px 0px 0px;margin:0px 0px 0px 0px;overflow:hidden;border:1px solid #CCCCCC;}</p>
<p>&lt;/style&gt;<br />
&lt;div id=&#8221;mapdiv&#8221;&gt;&lt;/div&gt;</p></blockquote>
<p>Thus i would have both weather and google map for the place by just storing one value in the database  i.e. &#8220;w&#8221; factor.</p>
<p>Thanks !! Ushainformatique Development Team</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/05/02/implement-yahoo-weather-on-your-site-along-with-google-map/feed/</wfw:commentRss>
		<slash:comments>54</slash:comments>
		</item>
		<item>
		<title>Usage of Data Transfer Object (DTO) Pattern in PHP</title>
		<link>http://ushainformatique.com/blog/2010/04/27/usage-of-data-transfer-object-dto-pattern-in-php/</link>
		<comments>http://ushainformatique.com/blog/2010/04/27/usage-of-data-transfer-object-dto-pattern-in-php/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 06:39:49 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Transfer Objects]]></category>
		<category><![CDATA[DTO Design Pattern]]></category>
		<category><![CDATA[DTO design pattern in PHP]]></category>
		<category><![CDATA[PHP Design Patterns]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=29</guid>
		<description><![CDATA[Data Transfer Object is a heavily used design pattern used in the development of web applications requiring database interaction in J2EE. It makes the life of a developer highly easy in managing the data that is being transferred and provides a secured way of transferring the data between layers.
When i switch from J2EE to PHP [...]]]></description>
			<content:encoded><![CDATA[<p>Data Transfer Object is a heavily used design pattern used in the development of web applications requiring database interaction in J2EE. It makes the life of a developer highly easy in managing the data that is being transferred and provides a secured way of transferring the data between layers.</p>
<p>When i switch from J2EE to PHP and with the release of PHP5, it suddenly comes to my mind to use this concept along with Data Access Object pattern (which i will explain in my next post) from J2EE in PHP  and it worked wonderfully for me to meet any level of complex applications.</p>
<p><em><strong>What is a Data object</strong></em>?</p>
<p>First of all, we need to understand as what is a data object. A data object is a class representing a table in the database with the field names <em><strong>exactly</strong></em> same as database column names. It contains the getter and setter methods for these fields.</p>
<p>Let&#8217;s say i have a table called tbl_employee having columns as</p>
<p>- id (int 10)</p>
<p>- name ( varchar(50))</p>
<p>Now, the dataobject would typically look like</p>
<blockquote><p>public class Employee()</p>
<p>{</p>
<p>var $id;</p>
<p>var $name;</p>
<p>public function getId()</p>
<p>{</p>
<p>return $this-&gt;id;</p>
<p>}</p>
<p>public function setId($tempId)</p>
<p>{</p>
<p>$this-&gt;id=$tempId;</p>
<p>return $this-&gt;id;</p>
<p>}</p>
<p>public function getName()<br />
{<br />
return $this-&gt;name;<br />
}<br />
public function setName($tempName)<br />
{<br />
$this-&gt;name=$tempName;<br />
return $this-&gt;name;<br />
}</p>
<p>Now the next point is about using it and see how helpful it would turn out to be. The following function interacts with the database thus assuming database connection is available.</p>
<p>public function getEmployeeList()</p>
<p>{</p>
<p>$employeeList = array();</p>
<p>$query = &#8220;select * from tbl_employee order by name&#8221;;</p>
<p>$result = mysql_query($query);</p>
<p>while ($row=mysql_fetch_array($result))</p>
<p>{</p>
<p>$tempEmployeeDO = new EmployeeDO();</p>
<p>$tempEmployeeDO-&gt;setId($row['id']);</p>
<p>$tempEmployeeDO-&gt;setName($row['name']);</p>
<p>$employeeList[count($employeeList)] = $tempEmployeeDO;</p>
<p>}</p>
<p>return $employeeList;</p>
<p>}</p></blockquote>
<p>Thus the above function returns the list of employees containing data objects. On the front end you need to iterate through the list where each element is a DO and than use getter method to retrieve the values.</p>
<p>Start using it and you will realize that it makes your life pretty easy during development.</p>
<p>Enjoy!!</p>
<p>Ushainformatique Development Team</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/04/27/usage-of-data-transfer-object-dto-pattern-in-php/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>Database modeling with Microsoft Visio for an Existing MySQL Database</title>
		<link>http://ushainformatique.com/blog/2010/04/18/database-modelling-with-microsoft-visio-for-an-existing-mysql-database/</link>
		<comments>http://ushainformatique.com/blog/2010/04/18/database-modelling-with-microsoft-visio-for-an-existing-mysql-database/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 13:03:22 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[Database Modeling]]></category>
		<category><![CDATA[Database Modeling with Microsoft Visio]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySql with Microsoft Visio]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=24</guid>
		<description><![CDATA[In a SDLC, creating a database model diagram is an important step that needs to be taken to achieve the following
- Create a clear visualization of the Database for the system which makes the database understanding pretty easier
- It helps in derive out the classes required to be created by just looking into the database [...]]]></description>
			<content:encoded><![CDATA[<p>In a SDLC, creating a database model diagram is an important step that needs to be taken to achieve the following</p>
<p>- Create a clear visualization of the Database for the system which makes the database understanding pretty easier</p>
<p>- It helps in derive out the classes required to be created by just looking into the database modeling diagram in depth</p>
<p>If you are not able to buy the paid tool for UML modeling such as rational rose etc., it&#8217;s still achievable through Microsoft Visio. Following are the steps that need to be performed to create a model diagram from an existing MySQL database in Microsoft Visio which is called as Reverse Engineering</p>
<p>- First of all, download the ODBC driver for MySQL from the location http://dev.mysql.com/downloads/connector/odbc/5.1.html. Download the installable by selecting the appropriate one based on  your machine configuration (32 bit or 64 bit)</p>
<p>- Install the mysql connector</p>
<p>- After installation, open visio</p>
<p>- Go to File-&gt;New-&gt;Database-&gt;Database Model</p>
<p>- From Database Menu, select Reverse Engineer</p>
<p>- On the Create New Datasource screen displayed, click on User Data Source</p>
<p>- Provide a datasource name</p>
<p>- Select the mysql connector driver, click on Next</p>
<p>- Click Finish and your new datasource would be added and would come as selected</p>
<p>- Click on Next</p>
<p>- Enter the valid username and password to create the connection using the datasource</p>
<p>- Select Object Type to reverse engineers</p>
<p>- You would be asked to select the database</p>
<p>- On selecting database, tables would be displayed</p>
<p>- Select the tables you want to create the datamodel for</p>
<p>- On selecting the tables, you would be asked to create the model with shape or without shape</p>
<p>- I select the shaped one and the model is generated</p>
<p>It&#8217;s really a helpful tool for the beginner to start creating the Database Modeling Diagram from an existing Database</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/04/18/database-modelling-with-microsoft-visio-for-an-existing-mysql-database/feed/</wfw:commentRss>
		<slash:comments>89</slash:comments>
		</item>
		<item>
		<title>Code Formatting in Netbeans 6.8</title>
		<link>http://ushainformatique.com/blog/2010/04/17/code-formatting-in-netbeans-6-8/</link>
		<comments>http://ushainformatique.com/blog/2010/04/17/code-formatting-in-netbeans-6-8/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 12:39:12 +0000</pubDate>
		<dc:creator>Usha Informatique Team</dc:creator>
				<category><![CDATA[Netbeans]]></category>
		<category><![CDATA[Code Formatting]]></category>
		<category><![CDATA[Handle Braces in Netbeans]]></category>

		<guid isPermaLink="false">http://ushainformatique.com/blog/?p=20</guid>
		<description><![CDATA[In any project in web world, code formatting plays a key role during the development of the project as it makes the code review process very simple at least from readability point of view.
The more readable your code is the more easy it is to review it. Now, how to format the code in Netbeans [...]]]></description>
			<content:encoded><![CDATA[<p>In any project in web world, code formatting plays a key role during the development of the project as it makes the code review process very simple at least from readability point of view.</p>
<p>The more readable your code is the more easy it is to review it. Now, how to format the code in Netbeans 6.8.</p>
<p>There are two levels at which formatting can be performed in Netbeans 6.8.</p>
<p>1) At a global level &#8211; It&#8217;s applicable across all the projects for which netbeans would be used</p>
<p>2) At a project level &#8211; It is specific to a particular project</p>
<p>For the first option</p>
<p>a) Go to Tools-&gt;Options-&gt;Editor-&gt; Formatting</p>
<p>b) Please select the language for which you want to apply the formatting, for me it is PHP</p>
<p>c) Select the category, which could be Tabs and Indent or Braces</p>
<p>d) Put your option for Tabs and Indent in terms of tabs or if you choose to go with spaces</p>
<p>e) For braces, you can select new line, same line or preserve existing</p>
<p>This is pretty useful as if you are aware of it, it saves lot of effort from your end.</p>
<p>Enjoy working with Netbeans 6.8 !!</p>
]]></content:encoded>
			<wfw:commentRss>http://ushainformatique.com/blog/2010/04/17/code-formatting-in-netbeans-6-8/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
	</channel>
</rss>
