<?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>Bagesh Singh&#039;s Blog &#187; Home</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/category/others/home/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bageshsingh.com/bagesh-blog</link>
	<description>Shortest Distance to  Web Solutions &#38; Software Solutions</description>
	<lastBuildDate>Wed, 22 Feb 2012 18:42:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Programmer vs Tester</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-tester/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-tester/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 18:36:57 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[Acceptance testing]]></category>
		<category><![CDATA[Alpha testing]]></category>
		<category><![CDATA[Beta testing]]></category>
		<category><![CDATA[Black box testing]]></category>
		<category><![CDATA[Comparison testing]]></category>
		<category><![CDATA[Compatibility testing]]></category>
		<category><![CDATA[CONFORMANCE TESTING]]></category>
		<category><![CDATA[End-to-end testing]]></category>
		<category><![CDATA[Functional testing]]></category>
		<category><![CDATA[Incremental integration testing]]></category>
		<category><![CDATA[Install/uninstall testing]]></category>
		<category><![CDATA[Integration testing]]></category>
		<category><![CDATA[Load testing]]></category>
		<category><![CDATA[Performance testing]]></category>
		<category><![CDATA[Recovery testing]]></category>
		<category><![CDATA[Regression testing]]></category>
		<category><![CDATA[Sanity testing]]></category>
		<category><![CDATA[Security testing]]></category>
		<category><![CDATA[SMOKE TESTING]]></category>
		<category><![CDATA[SOME OTHER PEOPLE OR TESTER TOLD ME THESE TYPE OF TESTING]]></category>
		<category><![CDATA[Stress testing]]></category>
		<category><![CDATA[System testing]]></category>
		<category><![CDATA[Unit testing]]></category>
		<category><![CDATA[Usability testing]]></category>
		<category><![CDATA[White box testing]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1646</guid>
		<description><![CDATA[When Programmer Think about tester they always feel anger. When Tester Think about programmer they Smile. Do you know why because due to tester programmer always feel embarrassed because tester find some mistakes in his program. How the tester do in software. There is lots of testing types through which tester test the software or [...]]]></description>
			<content:encoded><![CDATA[<p>When Programmer Think about tester they always feel anger.</p>
<p>When Tester Think about programmer they Smile.</p>
<p>Do you know why because due to tester programmer always feel embarrassed because tester find some mistakes in his program.</p>
<p>How the tester do in software.</p>
<p>There is lots of testing types through which tester test the software or websites.</p>
<p>Hi fiend I am not the tester so I don’t have more idea about testing but yes because of my experience in web development and software development I face tester and his ideas and many more thing…. so I can explain about testing.</p>
<p>Some of the types is available in testing it may different from others.</p>
<p>Black box testing</p>
<p>White box testing</p>
<p>Unit testing</p>
<p>Incremental integration testing</p>
<p>Integration testing</p>
<p>Functional testing</p>
<p>System testing</p>
<p>End-to-end testing</p>
<p>Sanity testing</p>
<p>Regression testing</p>
<p>Acceptance testing</p>
<p>Load testing</p>
<p>Stress testing</p>
<p>Performance testing</p>
<p>Usability testing</p>
<p>Install/uninstall testing</p>
<p>Recovery testing</p>
<p>Security testing</p>
<p>Compatibility testing</p>
<p>Comparison testing</p>
<p>Alpha testing</p>
<p>Beta testing</p>
<p>SOME OTHER PEOPLE OR TESTER TOLD ME THESE TYPE OF TESTING</p>
<p>ACCEPTANCE TESTING</p>
<p>BLACK BOX TESTING</p>
<p>COMPATIBILITY TESTING</p>
<p>CONFORMANCE TESTING</p>
<p>FUNCTIONAL TESTING</p>
<p>INTEGRATION TESTING</p>
<p>LOAD TESTING</p>
<p>PERFORMANCE TESTING</p>
<p>REGRESSION TESTING</p>
<p>SMOKE TESTING</p>
<p>STRESS TESTING</p>
<p>SYSTEM TESTING</p>
<p>UNIT TESTING</p>
<p>WHITE BOX TESTING</p>
<p>I am a programmer so I know problem creation of tester not type of testing I feel ……. when tester find out some bug in my application but water goes out of my head when he suggest according to</p>
<p>his opinion. But I want to make aware to all my friends programmer don’t believe on tester when he/she suggest don’t hesitate to told him to send a mail and cc to manager which you are suggesting. This will be good way to work with tester otherwise if you change your application according to his eye the what will be next you can’t imagine some time boss asked about these changes then they are just say it was my opinion and programmer changed so what I do. This will be language of tester when his/her neck in boss cabin.</p>
<p>Some tester without knowing the application start testing. What happens that time tester get more bug or No more bug so every programmer should train him on his/her application which he developed. Otherwise unnecessary you will be let to deliver you application. and this will make bad impression in office.</p>
<p>Some programmer leave bug and try to hide them but this is not the professional way to be a</p>
<p>programmer if you know the bug then it should solved before tester test because you know tester will send you again to solve and the bug list mail will goes to your project manager so don’t ignore any small bug. not even bug try to make some good website or application.</p>
<p>Don’t fight with tester try to be friend but not general friend professional friend it means</p>
<p>tester always think positive about you that “you made means no bug” that sentence you should expect from tester.</p>
<p>Do Bug Free Program and be friend of tester this is the main mantra about programming.</p>
<div id="seo_alrp_related"><h2>Posts Related to Programmer vs Tester</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/testers-vs-programmers-in-company/" rel="bookmark">Testers Vs Programmers In Company.</a></h3><p>When Programmer Think about tester they always feel anger. When Tester Think about programmer they Smile. Do you know why because due to tester programmer ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/istqb-moctest-second-part/" rel="bookmark">ISTQB-MocTest  second part</a></h3><p>1. COTS is known as (1M) A. Commercial off the shelf software B. Compliance of the software C. Change control of the software D. Capable off the shelf software ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/white-box-testing-techniques/" rel="bookmark">White Box Testing Techniques</a></h3><p>The following list of white box techniques is from BS79252: Statement testing Branch Decision Testing. Data Flow Testing. Branch Condition Testing. . Branch Condition Combination ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/black-box-testing-techniques/" rel="bookmark">Black Box Testing Techniques</a></h3><p>The following list of black box techniques is from BS 7925-2: Equivalent Partitioning. Boundary Value Analysis State Transition Testing Cause-Effect Graphing Syntax Testing</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/istqb-moctest-first-sample-of-interview-question/" rel="bookmark">ISTQB-MocTest first sample of interview  question</a></h3><p>___________ Testing will be performed by the people at client own locations (1M) A. Alpha testing B. Field testing C. Performance testing D. System testing System testing ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-tester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testers Vs Programmers In Company.</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/09/testers-vs-programmers-in-company/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/09/testers-vs-programmers-in-company/#comments</comments>
		<pubDate>Fri, 09 Sep 2011 18:28:35 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[Programmers]]></category>
		<category><![CDATA[Programmers Vs Testers]]></category>
		<category><![CDATA[Testers]]></category>
		<category><![CDATA[Testers Vs Programmers]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1643</guid>
		<description><![CDATA[When Programmer Think about tester they always feel anger. When Tester Think about programmer they Smile. Do you know why because due to tester programmer always feel embarrassed because tester find some mistakes in his program. How the tester do in software. There is lots of testing types through which tester test the software or [...]]]></description>
			<content:encoded><![CDATA[<p>When Programmer Think about tester they always feel anger.</p>
<p>When Tester Think about programmer they Smile.</p>
<p>Do you know why because due to tester programmer always feel embarrassed because tester find some mistakes in his program.</p>
<p>How the tester do in software.</p>
<p>There is lots of testing types through which tester test the software or websites.</p>
<p>Hi fiend I am not the tester so I don&#8217;t have more idea about testing but yes because of my experience in web development and software development I face tester and his ideas and many more thing&#8230;. so I can explain about testing.</p>
<p>Some of the types is available in testing it may different from others this is like history.</p>
<p>Black box testing – Internal system design is not considered in this type of testing. Tests are based on requirements and functionality.</p>
<p>White box testing – This testing is based on knowledge of the internal logic of an application’s code. Also known as Glass box Testing. Internal software and code working should be known for this type of testing. Tests are based on coverage of code statements, branches, paths, conditions.</p>
<p>Unit testing – Testing of individual software components or modules. Typically done by the programmer and not by testers, as it requires detailed knowledge of the internal program design and code. may require developing test driver modules or test harnesses.</p>
<p>Incremental integration testing – Bottom up approach for testing i.e continuous testing of an application as new functionality is added; Application functionality and modules should be independent enough to test separately. done by programmers or by testers.</p>
<p>Integration testing – Testing of integrated modules to verify combined functionality after integration. Modules are typically code modules, individual applications, client and server applications on a network, etc. This type of testing is especially relevant to client/server and distributed systems.</p>
<p>Functional testing – This type of testing ignores the internal parts and focus on the output is as per requirement or not. Black-box type testing geared to functional requirements of an application.</p>
<p>System testing – Entire system is tested as per the requirements. Black-box type testing that is based on overall requirements specifications, covers all combined parts of a system.</p>
<p>End-to-end testing – Similar to system testing, involves testing of a complete application environment in a situation that mimics real-world use, such as interacting with a database, using network communications, or interacting with other hardware, applications, or systems if appropriate.</p>
<p>Sanity testing &#8211; Testing to determine if a new software version is performing well enough to accept it for a major testing effort. If application is crashing for initial use then system is not stable enough for further testing and build or application is assigned to fix.</p>
<p>Regression testing – Testing the application as a whole for the modification in any module or functionality. Difficult to cover all the system in regression testing so typically automation tools are used for these testing types.</p>
<p>Acceptance testing -Normally this type of testing is done to verify if system meets the customer specified requirements. User or customer do this testing to determine whether to accept application.</p>
<p>Load testing – Its a performance testing to check system behavior under load. Testing an application under heavy loads, such as testing of a web site under a range of loads to determine at what point the system’s response time degrades or fails.</p>
<p>Stress testing – System is stressed beyond its specifications to check how and when it fails. Performed under heavy load like putting large number beyond storage capacity, complex database queries, continuous input to system or database load.</p>
<p>Performance testing – Term often used interchangeably with ‘stress’ and ‘load’ testing. To check whether system meets performance requirements. Used different performance and load tools to do this.</p>
<p>Usability testing – User-friendliness check. Application flow is tested, Can new user understand the application easily, Proper help documented whenever user stuck at any point. Basically system navigation is checked in this testing.</p>
<p>Install/uninstall testing &#8211; Tested for full, partial, or upgrade install/uninstall processes on different operating systems under different hardware, software environment.</p>
<p>Recovery testing – Testing how well a system recovers from crashes, hardware failures, or other catastrophic problems.</p>
<p>Security testing – Can system be penetrated by any hacking way. Testing how well the system protects against unauthorized internal or external access. Checked if system, database is safe from external attacks.</p>
<p>Compatibility testing – Testing how well software performs in a particular hardware/software/operating system/network environment and different combination s of above.</p>
<p>Comparison testing – Comparison of product strengths and weaknesses with previous versions or other similar products.</p>
<p>Alpha testing – In house virtual user environment can be created for this type of testing. Testing is done at the end of development. Still minor design changes may be made as a result of such testing.</p>
<p>Beta testing – Testing typically done by end-users or others. Final testing before releasing application for commercial purpose.</p>
<p>SOME OTHER PEOPLE OR TESTER TOLD ME THESE TYPE OF TESTING</p>
<p>ACCEPTANCE TESTING</p>
<p>Testing to verify a product meets customer specified requirements. A customer usually does this type of testing on a product that is developed externally.</p>
<p>BLACK BOX TESTING</p>
<p>Testing without knowledge of the internal workings of the item being tested. Tests are usually functional.</p>
<p>COMPATIBILITY TESTING</p>
<p>Testing to ensure compatibility of an application or Web site with different browsers, OSs, and hardware platforms. Compatibility testing can be performed manually or can be driven by an automated functional or regression test suite.</p>
<p>CONFORMANCE TESTING</p>
<p>Verifying implementation conformance to industry standards. Producing tests for the behavior of an implementation to be sure it provides the portability, interoperability, and/or compatibility a standard defines.</p>
<p>FUNCTIONAL TESTING</p>
<p>Validating an application or Web site conforms to its specifications and correctly performs all its required functions. This entails a series of tests which perform a feature by feature validation of behavior, using a wide range of normal and erroneous input data. This can involve testing of the product&#8217;s user interface, APIs, database management, security, installation, networking, etcF testing can be performed on an automated or manual basis using black box or white box methodologies.</p>
<p>INTEGRATION TESTING</p>
<p>Testing in which modules are combined and tested as a group. Modules are typically code modules, individual applications, client and server applications on a network, etc. Integration Testing follows unit testing and precedes system testing.</p>
<p>LOAD TESTING</p>
<p>Load testing is a generic term covering Performance Testing and Stress Testing.</p>
<p>PERFORMANCE TESTING</p>
<p>Performance testing can be applied to understand your application or web site&#8217;s scalability, or to benchmark the performance in an environment of third party products such as servers and middleware for potential purchase. This sort of testing is particularly useful to identify performance bottlenecks in high use applications. Performance testing generally involves an automated test suite as this allows easy simulation of a variety of normal, peak, and exceptional load conditions.</p>
<p>REGRESSION TESTING</p>
<p>Similar in scope to a functional test, a regression test allows a consistent, repeatable validation of each new release of a product or Web site. Such testing ensures reported product defects have been corrected for each new release and that no new quality problems were introduced in the maintenance process. Though regression testing can be performed manually an automated test suite is often used to reduce the time and resources needed to perform the required testing.</p>
<p>SMOKE TESTING</p>
<p>A quick-and-dirty test that the major functions of a piece of software work without bothering with finer details. Originated in the hardware testing practice of turning on a new piece of hardware for the first time and considering it a success if it does not catch on fire.</p>
<p>STRESS TESTING</p>
<p>Testing conducted to evaluate a system or component at or beyond the limits of its specified requirements to determine the load under which it fails and how. A graceful degradation under load leading to non-catastrophic failure is the desired result. Often Stress Testing is performed using the same process as Performance Testing but employing a very high level of simulated load.</p>
<p>SYSTEM TESTING</p>
<p>Testing conducted on a complete, integrated system to evaluate the system&#8217;s compliance with its specified requirements. System testing falls within the scope of black box testing, and as such, should require no knowledge of the inner design of the code or logic.</p>
<p>UNIT TESTING</p>
<p>Functional and reliability testing in an Engineering environment. Producing tests for the behavior of components of a product to ensure their correct behavior prior to system integration.</p>
<p>WHITE BOX TESTING</p>
<p>Testing based on an analysis of internal workings and structure of a piece of software. Includes techniques such as Branch Testing and Path Testing. Also known as Structural Testing and Glass Box Testing.</p>
<p>I am a programmer so I know problem creation of tester not type of testing I feel &#8230;&#8230;. when tester find out some bug in my application but water goes out of my head when he suggest according to</p>
<p>his opinion. But I want to make aware to all my friends programmer don&#8217;t believe on tester when he/she suggest don&#8217;t hesitate to told him to send a mail and cc to manager which you are suggesting. This will be good way to work with tester otherwise if you change your application according to his eye the what will be next you can&#8217;t imagine some time boss asked about these changes then they are just say it was my opinion and programmer changed so what I do. This will be language of tester when his/her neck in boss cabin.</p>
<p>Some tester without knowing the application start testing. What happens that time tester get more bug or No more bug so every programmer should train him on his/her application which he developed. Otherwise unnecessary you will be let to deliver you application. and this will make bad impression in office.</p>
<p>Some programmer leave bug and try to hide them but this is not the professional way to be a</p>
<p>programmer if you know the bug then it should solved before tester test because you know tester will send you again to solve and the bug list mail will goes to your project manager so don&#8217;t ignore any small bug. not even bug try to make some good website or application.</p>
<p>Don&#8217;t fight with tester try to be friend but not general friend professional friend it means</p>
<p>tester always think positive about you that &#8220;you made means no bug&#8221; that sentence you should expect from tester.</p>
<p>Do Bug Free Program and be friend of tester this is the main mantra about programming.</p>
<div id="seo_alrp_related"><h2>Posts Related to Testers Vs Programmers In Company.</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-tester/" rel="bookmark">Programmer vs Tester</a></h3><p>When Programmer Think about tester they always feel anger. When Tester Think about programmer they Smile. Do you know why because due to tester programmer ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/white-box-testing-techniques/" rel="bookmark">White Box Testing Techniques</a></h3><p>The following list of white box techniques is from BS79252: Statement testing Branch Decision Testing. Data Flow Testing. Branch Condition Testing. . Branch Condition Combination ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/istqb-moctest-second-part/" rel="bookmark">ISTQB-MocTest  second part</a></h3><p>1. COTS is known as (1M) A. Commercial off the shelf software B. Compliance of the software C. Change control of the software D. Capable off the shelf software ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/black-box-testing-techniques/" rel="bookmark">Black Box Testing Techniques</a></h3><p>The following list of black box techniques is from BS 7925-2: Equivalent Partitioning. Boundary Value Analysis State Transition Testing Cause-Effect Graphing Syntax Testing</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/istqb-moctest-first-sample-of-interview-question/" rel="bookmark">ISTQB-MocTest first sample of interview  question</a></h3><p>___________ Testing will be performed by the people at client own locations (1M) A. Alpha testing B. Field testing C. Performance testing D. System testing System testing ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/09/testers-vs-programmers-in-company/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build a file sharing application in cakephp</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/09/build-a-file-sharing-application-in-cakephp/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/09/build-a-file-sharing-application-in-cakephp/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 21:58:42 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[cakephp]]></category>
		<category><![CDATA[cakephp interview question]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHP Third Party Tools]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1635</guid>
		<description><![CDATA[The honeymoon is over baby. Now it’s time for the real work to begin. This iteration of our CakePHP tutorial series will result in your very own file-sharing tool. This is handy in the situation that you have a file you need to send to a business partner or client, or share with a friend, [...]]]></description>
			<content:encoded><![CDATA[<p>The honeymoon is over baby. Now it’s time for the real work to begin. This iteration of our CakePHP tutorial series will result in your very own file-sharing tool. This is handy in the situation that you have a file you need to send to a business partner or client, or share with a friend, but you still want to retain control over who gets access to each specific file. For example, you may only want a client to access a file for a week, so we’ll build a system where you can remove that access at any time. What’s more, it’ll be quick, easy, and extensible once we’re done.</p>
<p>&nbsp;</p>
<div></div>
<p>For each file, we want to associate it with a user for ownership, but we also want to be able to associate it with many other users for sharing (read access). So we need to define two separate associations from file to user. We’re going to manage the sharing access with an association called “Has and belongs to many” or HABTM for short. HABTM utilises a join table to associate the two records, and has a standard within CakePHP that we’ll follow so the framework can do all the heavy lifting for us:</p>
<pre>CREATE DATABASE `fileshare`;
USE `fileshare`;

CREATE TABLE `uploads` (
	`id` CHAR(36) NOT NULL PRIMARY KEY,
	`user_id` CHAR(36) NOT NULL,
	`title` VARCHAR(45) NOT NULL,
	`description` TEXT,
	`filename` VARCHAR(255) NOT NULL,
	`filesize` INT(11) UNSIGNED NOT NULL DEFAULT 0,
	`filemime` VARCHAR(45) NOT NULL DEFAULT 'text/plain',
	`created` DATETIME,
	`modified` DATETIME
);

CREATE TABLE `users` (
	`id` CHAR(36) NOT NULL PRIMARY KEY,
	`username` VARCHAR(45) NOT NULL,
	`password` VARCHAR(255) NOT NULL,
	`email` VARCHAR(255) NOT NULL,
	`created` DATETIME,
	`modified` DATETIME
);</pre>
<p>The join table we mentioned identifies users that have been allowed access to specified files. The standards specify that a join table for a HABTM association is to be the tables in their plural form, joined with an underscore and listed in alphabetical order:</p>
<pre>CREATE TABLE `uploads_users` (
  `id` CHAR(36) NOT NULL PRIMARY KEY,
  `upload_id` CHAR(36) NOT NULL,
  `user_id` CHAR(36) NOT NULL
);</pre>
<p>Create your tables in a new database, and we’ll push on to baking the project and getting the basics running.</p>
<h2>Ready, set… bake!</h2>
<p>Bake is a special console command that ships with CakePHP, and is run from the console. In order for this to work effectively the cake/console path within the CakePHP package needs to be in your PATH environment variable. You can achieve this with the following in your shell: $ export PATH=”$PATH:/path/to/cakephp/cake/console” And of course you’ll need PHP available on the command line (usually available in a php-cli package, or similar). To create the skeleton structure for your project, run the following in your shell:</p>
<pre>$ cake bake project fileshare
$ cd fileshare</pre>
<p>Next, configure the app to connect to the database. Change the settings as shown in the following code in your config/database.php file to the appropriate settings for your databaseL</p>
<pre>class DATABASE_CONFIG {
	var $default = array(
		'driver' =&gt; 'mysql',
		'persistent' =&gt; false,
		'host' =&gt; 'localhost',
		'login' =&gt; 'username',
		'password' =&gt; 'password',
		'database' =&gt; 'fileshare',
		'prefix' =&gt; '',
	);
}</pre>
<p>Setting up the “default” connection is enough. And while we’re baking and having CakePHP handle all the hard work, lets bake the controllers, models and views to get the basis of our project in place.</p>
<pre>$ cake bake all user
$ cake bake all upload</pre>
<p>What we have at this stage is a completely ready-to-use website that associates users with many uploads and enables us to populate the database in an easy-to-use manner. But thus far, there’s no actual file upload capability, so we need to modify what CakePHP has baked for us to provide additional functionality processing the file uploads and to prevent people from adding and modifying other users’ information. Further to that, we want to secure the whole application so that only authenticated users can modify data.</p>
<h2>Locking things down</h2>
<p>We already have a ‘users’ table, and the user addition is working as part of the baking process if you browse to your application and append users to the URL. For example: http://localhost/fileshare/users. So what do we need to do? Well, passwords at this stage are being stored in cleartext, and we don’t seem to be asked to log in. Open up the app_controller.php file in the root of your project. This is an empty controller from which all the other controllers in the application inherit functionality. Anything we implement here will be used in all our controllers, so this is the perfect place to enforce logins. Add the Auth and Session components. Your AppController will now look like this:</p>
<pre>&lt;?php
class AppController extends Controller {
  var $components = array(‘Auth’, ‘Session’);
}
?&gt;</pre>
<p>If you try to refresh your users list, you’ll be presented with an error indicating that the login action doesn’t exist. If you look carefully, the URL has also been changed to /users/login. Fortunately all the juicy hard stuff has been implemented in CakePHP for us, so all we need to do is provide the action (function) on the controller, and a login form for users to view. Open up controllers/users_controller.php and add the login action:</p>
<pre>function login() {
}</pre>
<p>That’s not a mistake, it’s an empty function, and it’s all we need for authentication to log in on the controller side.</p>
<div>
<h2>Class Conflicts</h2>
<p>Without the availability of PHP namespaces, we can’t name classes the same as any that might be used from the CakePHP framework. Since CakePHP provides a File class, we’ve had to avoid calling our model in this example “File”, as a conflict would arise with class naming. As such, “Upload” has been used in its place. For a list of all classes in CakePHP, see the public API: http://api.cakephp.org.</p>
</div>
<p>Before we get too ahead of ourselves, we need to ensure that we can register a user in case you have not already registered one. Since we’re about to complete the user authentication section, we’d be locked out of all functionality and if we didn’t make an exception for the user registration page, we’d never be able to get into our funky new system. Create a beforeFilter method on the users controller, and add the following to tell the Auth component that we’re allowed to visit the register page even if we have not yet logged in:</p>
<pre>function beforeFilter() {
  $this-&gt;Auth-&gt;allow(‘add’);
  return parent::beforeFilter();
}</pre>
<p>Create the login view in a new file: views/users/login.ctp, as described here:</p>
<pre>&lt;div&gt;
&lt;?php echo $this-&gt;Form-&gt;create('User');?&gt;
	&lt;fieldset&gt;
 		&lt;legend&gt;&lt;?php __('Login'); ?&gt;&lt;/legend&gt;
	&lt;?php
	echo $this-&gt;Form-&gt;input('username');
	echo $this-&gt;Form-&gt;input('password');
	?&gt;
	&lt;/fieldset&gt;
&lt;?php echo $this-&gt;Form-&gt;end(__('Submit', true));?&gt;
&lt;/div&gt;</pre>
<p>Refresh the page that was giving an error message, and you’ll be presented with a login form. Notice that you will be allowed to visit the /users/add page, but everything else will be redirected to the /users/login page. Feel free at this point to register yourself a user. It will be useful in testing further points in the application. Take a moment to check out your database. You’ll notice that the password is hashed for us automatically. Awesome! It’s also handy to clean up some of the automatically generated fields and inputs that we won’t be using, to ensure that users only have access to things we permit. So remove the following input from both the user add and edit views in views/users/add.ctp and views/users/edit.ctp:</p>
<pre>echo $this-&gt;Form-&gt;input(‘Upload’);</pre>
<div><img src="http://www.tuxradar.com/files/cakephp/cake_03_02.jpg" alt="The user index is accessible until authentication is added." />The user index is accessible until authentication is added.</p>
</div>
<h2>Enabling file uploads</h2>
<p>It’s high time we got some file uploading action happening. First up, let’s make an uploads directory under the project directory to place our uploaded files, then assign ownership to the user running your web server. On some distributions this user is www-data, on others it’s apache or www. You’ll need to specify the appropriate user for your system.</p>
<pre>$ mkdir uploads
$ chown www-data uploads</pre>
<p>Time to dive into some code! Let’s start by adjusting the upload add page to accept files, and store them in a safe manner. The bake process has generated a fairly good form for us, but we’re going to remove a couple of the automatically generated fields and replace them with a file upload field. The columns we defined in our database are primarily for automatic population. The file upload will provide all the data we need. Remove the filename, filesize and filemime inputs from the upload add view in views/uploads/add.ctp, and add in a file input. We didn’t create a column called file in the database, so CakePHP isn’t going to do all the fancy behind-the-scenes work for that field, and we also need to tell it what type that field needs to be for the file input to be generated correctly. The other small change we’re making is to remove the user_id input that CakePHP had generated for us. Instead, we’ll add some code in our controller to automatically assign files to the user who is currently logged in. Your form inputs should now look like this:</p>
<pre>&lt;?php echo $this-&gt;Form-&gt;create(‘Upload’, array(‘type’ =&gt; ‘file’));?&gt;
  &lt;fieldset&gt;
     &lt;legend&gt;&lt;?php __(‘Add Upload’); ?&gt;&lt;/legend&gt;
  &lt;?php
  echo $this-&gt;Form-&gt;input(‘title’);
  echo $this-&gt;Form-&gt;input(‘description’);
  echo $this-&gt;Form-&gt;input(‘file’, array(‘type’ =&gt; ‘file’));
  echo $this-&gt;Form-&gt;input(‘User’);
  ?&gt;
  &lt;/fieldset&gt;
&lt;?php echo $this-&gt;Form-&gt;end(__(‘Submit’, true));?&gt;</pre>
<div><img src="http://www.tuxradar.com/files/cakephp/cake_03_04.jpg" alt="Enabling file uploads is simple." />Enabling file uploads is simple.</p>
</div>
<h2>Processing the uploaded file</h2>
<p>Sure, we’ve got a file in place, but we actually need to handle the file in some manner to show up an error when the file is not correctly uploaded, and to save it in our prepared writable uploads folder when it’s been completed successfully. For this we open up controllers/uploads_controller.php in the baked project, and modify the function add() to process the file if it’s available. On the third line of this function, the code attempts to save the model data. Modify the if statement to call a function that we’ll write in a moment called uploadFile(): if ($this-&gt;uploadFile() &amp;&amp; $this-&gt;Upload-&gt;save($this-&gt;data)) {</p>
<p>Sounds easy enough, doesn’t it? Now let’s create the uploadFile() function in the same controller:</p>
<pre>function uploadFile() {
  $file = $this-&gt;data[‘Upload’][‘file’];
  if ($file[‘error’] === UPLOAD_ERR_OK) {
    $id = String::uuid();
    if (move_uploaded_file($file[‘tmp_name’], APP.’uploads’.DS.$id)) {
      $this-&gt;data[‘Upload’][‘id’] = $id;
      $this-&gt;data[‘Upload’][‘user_id’] = $this-&gt;Auth-&gt;user(‘id’);
      $this-&gt;data[‘Upload’][‘filename’] = $file[‘name’];
      $this-&gt;data[‘Upload’][‘filesize’] = $file[‘size’];
      $this-&gt;data[‘Upload’][‘filemime’] = $file[‘type’];
      return true;
    }
  }
  return false;
}</pre>
<p>Again, we’re keeping things simple. We upload the file, and if we’re able to move it successfully into place, we return true. In the process of doing this, we are manually generating an ID which we use as a safe filesystem name for storage. This eliminates any issues that users may attempt to introduce with weird and potentially system-damaging filenames that would otherwise be directly stored on your filesystem. Manually generating the UUID with String::uuid() removes this security hole, and ensures a safe file upload, while maintaining the original filename in the database to send to the user when downloading.</p>
<p>The next thing we’re going to integrate is the ability to download files. But before going too far, try adding a couple of files. You’ll see them successfully being added to the database, and if you look at the uploads directory we created, matching ID named files start appearing within. If you experience any issues at this point, ensure that your web server user has write access to the uploads directory.</p>
<p>The other cool thing we’re doing here is assigning the user with $this-&gt;Auth-&gt;user(‘id’) which is the ID of the currently logged-in user. Since we locked down the security earlier, we know that users need to be logged in to reach this page, so the value will always be present and valid.</p>
<h2>Cleaning up associations</h2>
<p>You’ll notice that we’ve doubled up on our associations for both the User and Upload model. Take for example the User model in models/user.php; CakePHP has generated a hasMany and a hasAndBelongsToMany association both with the index Upload. This just won’t do, because the clash in naming will cause incorrect data to output in the views. Change the hasAndBelongsToMany association in the User model to be SharedUpload. And similarly for the Upload model in models/upload.php, change the HABTM association to be SharedUser:</p>
<pre>// User Model
var $hasAndBelongsToMany = array(
  ‘SharedUpload’ =&gt; array(
    ‘className’ =&gt; ‘Upload’,
    ...

// Upload Model
var $hasAndBelongsToMany = array(
  ‘SharedUser’ =&gt; array(
    ‘className’ =&gt; ‘User’,
      ..</pre>
<p>In order for these association key changes to correctly render in the views, you’ll need to change the index referenced on the views in the related section at the bottom of the view indexes. In views/users/view.ctp, the following two lines:</p>
<pre>&lt;?php if (!empty($user[‘pload’])):?&gt;
foreach ($user[‘Upload’] as $upload):</pre>
<p>are changed to:</p>
<pre>&lt;?php if (!empty($user[‘SharedUpload’])):?&gt;
foreach ($user[‘SharedUpload’] as $upload):</pre>
<p>At this point you can register a new user, log in to the system, upload files and assign users. We’ve achieved a massive amount of functionality for minimal code and effort. Give the system a good test before moving on the the next step.</p>
<h2>Viewing and downloading files</h2>
<p>If you have played around with the navigation in the views we have already, you’ll have come across the view page for one of your uploaded files. It shows all the meta information about the file, but at this point you can’t retrieve the file itself. Let’s tweak a few things to enable downloads so we can get at the files. The first thing to do is add a link to the view file views/uploads/view.ctp. You can add this wherever you like (I prefer to add it at the bottom of the existing data):</p>
<pre>&lt;dt&lt;?php if ($i % 2 == 0) echo $class;?&gt;&gt;&lt;?php __(‘Download’); ?&gt;&lt;/dt&gt;
&lt;dd&lt;?php if ($i++ % 2 == 0) echo $class;?&gt;&gt;
  &lt;?php echo $this-&gt;Html-&gt;link(__(‘Download’, true), array(‘action’ =&gt; ‘download’, $upload[‘Upload’][‘id’])); ?&gt;

&lt;/dd&gt;</pre>
<p>With the link created, it’s time to get our hands dirty again and put together the action for the controller to handle the file download. Open up your UploadsController in controllers/uploads_controller.php one more time and add the following download function. This forces download, and returns the file to the user with the original filename that was present when the file was uploaded. Here&#8217;s the code:</p>
<pre>function download($id = null) {
	if (!$id) {
		$this-&gt;Session-&gt;setFlash(__('Invalid id for upload', true));
		$this-&gt;redirect(array('action' =&gt; 'index'));
	}
	$this-&gt;Upload-&gt;bindModel(array('hasOne' =&gt; array('UploadsUser')));
	$upload = $this-&gt;Upload-&gt;find('first', array(
		'conditions' =&gt; array(
			'Upload.id' =&gt; $id,
			'OR' =&gt; array(
				'UploadsUser.user_id' =&gt; $this-&gt;Auth-&gt;user('id'),
				'Upload.user_id' =&gt; $this-&gt;Auth-&gt;user('id'),
			),
		)
	));
	if (!$upload) {
		$this-&gt;Session-&gt;setFlash(__('Invalid id for upload', true));
		$this-&gt;redirect(array('action' =&gt; 'index'));
	}
	$this-&gt;view = 'media';
	$filename = $upload['Upload']['filename'];
	$this-&gt;set(array(
		'id' =&gt; $upload['Upload']['id'],
		'name' =&gt; substr($filename, 0, strrpos($filename, '.')),
		'extension' =&gt; substr(strrchr($filename, '.'), 1),
		'path' =&gt; APP.'uploads'.DS,
		'download' =&gt; true,
	));
}</pre>
<div>
<h2>Tutorial Code</h2>
<p>The code for this article has been made available on GitHub under my account http://github.com/predominant/cakephp_linux_format. You can grab the code from here if you had any issues with the code generation through the bake facility, or if you just want to get the application up and running, you can clone the code without going through each of the steps in the article.</p>
</div>
<p>You can now try out your download link, and you’ll get the file being downloaded via your browser! There’s a fair bit going on in this function, but believe me, there’s far more being taken care of by CakePHP that you don’t need to worry about. We’re first inspecting the ID to ensure it was supplied. Next, we try to lookup an upload record from the database with that ID, and while we’re in there, we ensure that the ID of the upload is associated with the currently logged-in user, or that the file was originally uploaded by the user who is logged in. In either case, we are allowed access. If that query failed, the user is attempting to access a file to which they have not specifically been granted permission, so we redirect them to the index list of files.</p>
<h2>Showing only what users can access</h2>
<p>In order to make the file list make sense for all users, you’ll also need to modify the index() action on the Uploads controller, to perform similar filtering to show only the files that are permitted in the users rendered list, otherwise it’ll clog up with files they don’t actually have access to see! Adjust the index action thus:</p>
<pre>function index() {
  $this-&gt;Upload-&gt;bindModel(array(‘hasOne’ =&gt; array(‘UploadsUser’)), false);
  $this-&gt;paginate = array(
    ‘conditions’ =&gt; array(
      ‘OR’ =&gt; array(
        ‘UploadsUser.user_id’ =&gt; $this-&gt;Auth-&gt;user(‘id’),
        ‘Upload.user_id’ =&gt; $this-&gt;Auth-&gt;user(‘id’),
      ),
    )
  );
  $this-&gt;set(‘uploads’, $this-&gt;paginate());
}</pre>
<p>We’ve had to add the false parameter on the bindModel() call this time to ensure that the pagination result came out correctly. Pagination takes two separate database results to return the data. The first of these determines the number of elements in the table that match the query, and the second actually retrieve the data. The false parameter tells CakePHP to retain the binding beyond a single query. The simple rule, of course, is that if you are using bindModel and pagination, you need to add false on the end.</p>
<p>The view() action also benefits from the same filtering:</p>
<pre>function view($id = null) {
  if (!$id) {
    $this-&gt;Session-&gt;setFlash(__(‘Invalid upload’, true));
$this-&gt;redirect(array(‘action’ =&gt; ‘index’));
  }

  $this-&gt;Upload-&gt;bindModel(array(‘hasOne’ =&gt; array(‘UploadsUser’)));
  $upload = $this-&gt;Upload-&gt;find(‘first’, array(
    ‘conditions’ =&gt; array(
      ‘Upload.id’ =&gt; $id,
      ‘OR’ =&gt; array(
        ‘UploadsUser.user_id’ =&gt; $this-&gt;Auth-&gt;user(‘id’),
        ‘Upload.user_id’ =&gt; $this-&gt;Auth-&gt;user(‘id’),
      ),
    )
  ));
  if (!$upload) {
    $this-&gt;Session-&gt;setFlash(__(‘Invalid upload’, true));
    $this-&gt;redirect(array(‘action’ =&gt; ‘index’));
  }
  $this-&gt;set(‘upload’, $upload);
}</pre>
<h2>Wrapping it up</h2>
<p>The only last nicety that would be required to take this site live is a logout function. And I’ll be kind enough to give you the code to put on the UsersController for logout:</p>
<pre>public function logout() {
  $this-&gt;redirect($this-&gt;Auth-&gt;logout());
}</pre>
<p>There’s no view required, and redirection happens as soon as the user hits the /users/logout URL, after destroying the session and logging out the user.</p>
<p>So we’ve built a secure, file-uploading, multi-user sharing web application, and it’s only taken 20 minutes or so to get it all done. From here, you can add extra functionality such as thumbnail icons to preview content that users have uploaded, or a different sharing mechanism to select users without exposing the complete user list to everyone. You can also enable email notifications for users that you are sharing files with. I hope you’ve enjoyed this tutorial, and I hope it’s useful for you either as a case study, or as a deployable solution for client file sharing.</p>
<div><img src="http://www.tuxradar.com/files/cakephp/cake_03_05.jpg" alt="The additional link enables us to download files that have been uploaded." />The additional link enables us to download files that have been uploaded.</p>
</div>
<div id="seo_alrp_related"><h2>Posts Related to Build a file sharing application in cakephp</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/uploading-largebig-files-in-php-using-htaccess-2/" rel="bookmark">Uploading large(big) files in PHP using .htaccess</a></h3><p>I’ve seen that many of my friends are struggling with the uploads of the bigger or larger files in PHP. After looking at their struggle, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-build-a-bookmark-site-in-cakephp/" rel="bookmark">how to Build a bookmark site in cakephp?</a></h3><p>If you've followed our last few tutorials, you'll be a CakePHP expert by now: you know how to navigate controllers, delve into the depths of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-build-web-apps-faster-in-cakephp/" rel="bookmark">How to Build Web Apps Faster in cakephp?</a></h3><p>The pressure is on. You’ve got limited time, and you need a system to catalogue your extensive movie collection in 15 minutes. Who ya gonna ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/05/a-solution-for-e-mail-handling-in-cakephp/" rel="bookmark">A solution for e-mail handling in CakePHP</a></h3><p>The emailComponent (cake\libs\controller\components\email.php) is a way for you to using the same concepts of layouts and view ctp files to send formated messages as text, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/21-things-you-must-know-about-cakephp/" rel="bookmark">21 Things You Must Know About CakePHP</a></h3><p>Easily creating static pages I needed to create several pages that didn't use any models and contained static data inside the default layout. My first ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/09/build-a-file-sharing-application-in-cakephp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to optimize mysql query and mysql database?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-mysql-query-and-mysql-database/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-mysql-query-and-mysql-database/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 20:41:37 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql interview question]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[Be wary of locks]]></category>
		<category><![CDATA[but bad for writes]]></category>
		<category><![CDATA[constants) is very fast]]></category>
		<category><![CDATA[Create your tables with a fixed-table format if possible]]></category>
		<category><![CDATA[Do as much as your filtering in SQL as you can]]></category>
		<category><![CDATA[Don't create indexes you aren't going to use]]></category>
		<category><![CDATA[Don't use SELECT * unless you must]]></category>
		<category><![CDATA[Firstly choose which table being used every time for delete]]></category>
		<category><![CDATA[HIGH_PRIORITY]]></category>
		<category><![CDATA[How to optimize mysql query and mysql database]]></category>
		<category><![CDATA[including NOT NULL if appropriate - don't rely on automatic type conversion]]></category>
		<category><![CDATA[Increase your buffer sizes so that MySQL can cache more]]></category>
		<category><![CDATA[Indexes are good for reads]]></category>
		<category><![CDATA[insert or update make a list and always repair these tables. after 15 days]]></category>
		<category><![CDATA[Load your data before adding indexes is faster than adding indexes first]]></category>
		<category><![CDATA[of]]></category>
		<category><![CDATA[once you optimize your query and database of mysql it will make your website and application very fast]]></category>
		<category><![CDATA[or DELAYED when it matters]]></category>
		<category><![CDATA[Prioritise your queries as LOW_PRIORITY]]></category>
		<category><![CDATA[SELECT foo IN (list]]></category>
		<category><![CDATA[There is lots of way to optimize mysql]]></category>
		<category><![CDATA[this is very good question for mysql interview best of luck hope this will help for your good career]]></category>
		<category><![CDATA[Use --log-slow-queries to see where your tables can be optimised]]></category>
		<category><![CDATA[Use default values for INSERT when you can]]></category>
		<category><![CDATA[use numbers instead of strings if you can]]></category>
		<category><![CDATA[Use OPTIMIZE TABLE and ANALYZE TABLE regularly]]></category>
		<category><![CDATA[Use SHOW STATUS to make sure your MySQL server is in good condition]]></category>
		<category><![CDATA[Use temporary tables rather than heavy PHP work]]></category>
		<category><![CDATA[Use the best data type]]></category>
		<category><![CDATA[Use the EXPLAIN keyword to see how MySQL will execute your query - make sure your indexes are being used!]]></category>
		<category><![CDATA[Use the most efficient table type for each table]]></category>
		<category><![CDATA[When joining tables]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1631</guid>
		<description><![CDATA[There is lots of way to optimize mysql. once you optimize your query and database of mysql it will make your website and application very fast. Firstly choose which table being used every time for delete, insert or update make a list and always repair these tables. after 15 days. this is very good question [...]]]></description>
			<content:encoded><![CDATA[<p>There is lots of way to optimize mysql. once you optimize your query and database of mysql it will make your website and application</p>
<p>very fast. Firstly choose which table being used every time for delete, insert or update make a list and always repair these tables.</p>
<p>after 15 days.</p>
<p>this is very good question for mysql interview best of luck hope this will help for your good career.</p>
<p>Prioritise your queries as LOW_PRIORITY, HIGH_PRIORITY, or DELAYED when it matters</p>
<p>Don&#8217;t use SELECT * unless you must</p>
<p>Use the EXPLAIN keyword to see how MySQL will execute your query &#8211; make sure your indexes are being used!</p>
<p>Load your data before adding indexes is faster than adding indexes first</p>
<p>Be wary of locks</p>
<p>Use &#8211;log-slow-queries to see where your tables can be optimised</p>
<p>Increase your buffer sizes so that MySQL can cache more</p>
<p>Use SHOW STATUS to make sure your MySQL server is in good condition</p>
<p>Don&#8217;t create indexes you aren&#8217;t going to use</p>
<p>Do as much as your filtering in SQL as you can</p>
<p>Indexes are good for reads, but bad for writes</p>
<p>Use OPTIMIZE TABLE and ANALYZE TABLE regularly</p>
<p>Create your tables with a fixed-table format if possible</p>
<p>Use the most efficient table type for each table</p>
<p>Use the best data type, including NOT NULL if appropriate &#8211; don&#8217;t rely on automatic type conversion</p>
<p>Use default values for INSERT when you can</p>
<p>Use temporary tables rather than heavy PHP work</p>
<p>SELECT foo IN (list, of, constants) is very fast</p>
<p>When joining tables, use numbers instead of strings if you can</p>
<div id="seo_alrp_related"><h2>Posts Related to How to optimize mysql query and mysql database?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-do-mysql-optimization/" rel="bookmark">how to do MySQL Optimization</a></h3><p>myisamchk is used to get information about your database tables or to check, repair, or optimize them. This command can check or repair MyISAM tables. ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2012/02/how-to-do-table-partition-in-mysql/" rel="bookmark">how to do table partition in mysql</a></h3><p>HI all of my php programmer. Mostly MYSQL DBA done the partitioning but if we talk about programmer then they are unable to do. so ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, I was the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/05/php-mysql-functions-list/" rel="bookmark">PHP Mysql Functions List</a></h3><p>mysql_affected_rows — Get number of affected rows in previous MySQL operation mysql_change_user — Change logged in user of the active connection mysql_client_encoding — Returns the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/php-export-database-schema-as-xml/" rel="bookmark">PHP: Export Database Schema as XML</a></h3><p>Sometimes it can be useful to have a dump of the current database schema. The script below reads the schema from a MySQL database and outputs ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-mysql-query-and-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to optimize php code.</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-php-code/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-php-code/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 20:40:19 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Php interview question]]></category>
		<category><![CDATA[As a last resort]]></category>
		<category><![CDATA[Avoid calling the dl() function]]></category>
		<category><![CDATA[Avoid mod_access if you can]]></category>
		<category><![CDATA[best of luck. What is the process for PHP code Optimisation]]></category>
		<category><![CDATA[big and small - they slow things down]]></category>
		<category><![CDATA[Compress your output to save network bandwidth]]></category>
		<category><![CDATA[Don't fret about Apache 2.0]]></category>
		<category><![CDATA[Don't rely on references without testing; they are rarely as effective as you'd think]]></category>
		<category><![CDATA[Get a good understanding of how garbage collection works]]></category>
		<category><![CDATA[How to optimize php code]]></category>
		<category><![CDATA[In this post we are going to learn how to optimize our php code]]></category>
		<category><![CDATA[Listen to all errors]]></category>
		<category><![CDATA[Optimise compilation of your PHP binary if possible]]></category>
		<category><![CDATA[Pre-increment where possible]]></category>
		<category><![CDATA[Priorities optimisation of tight loops for the most payback]]></category>
		<category><![CDATA[Store a local pointer to an array element to save indexing into the array each time you need it]]></category>
		<category><![CDATA[try inlining function]]></category>
		<category><![CDATA[Try to avoid using PHP in CGI mode]]></category>
		<category><![CDATA[Use persistent resource where appropriate]]></category>
		<category><![CDATA[Use the comma operator to join arguments when calling echo]]></category>
		<category><![CDATA[Use the Zend Optimizer and a code cache]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1629</guid>
		<description><![CDATA[In this post we are  going to learn how to optimize our php code. once you optimize your php code then your applicationa and website will be very fast this will make quality code. Hi php programmer don&#8217;t forget these rules if you want to be good in php and want to work in MNC [...]]]></description>
			<content:encoded><![CDATA[<p>In this post we are  going to learn how to optimize our php code.</p>
<p>once you optimize your php code then your applicationa and website will be very fast<br />
this will make quality code. Hi php programmer don&#8217;t forget these rules if you want to<br />
be good in php and want to work in MNC because all mnc and all good companies follow<br />
these rules strictly even this is gud question for interview for php. best of luck.</p>
<p>What is the process for PHP code Optimisation.</p>
<p>Use the Zend Optimizer and a code cache</p>
<p>Use the comma operator to join arguments when calling echo</p>
<p>Priorities optimisation of tight loops for the most payback</p>
<p>Pre-increment where possible</p>
<p>Don&#8217;t rely on references without testing; they are rarely as effective as you&#8217;d think</p>
<p>Get a good understanding of how garbage collection works</p>
<p>Listen to all errors, big and small &#8211; they slow things down</p>
<p>Store a local pointer to an array element to save indexing into the array each time you need it</p>
<p>Compress your output to save network bandwidth</p>
<p>Try to avoid using PHP in CGI mode</p>
<p>Avoid calling the dl() function</p>
<p>Use persistent resource where appropriate</p>
<p>Optimise compilation of your PHP binary if possible</p>
<p>Avoid mod_access if you can</p>
<p>Don&#8217;t fret about Apache 2.0</p>
<p>As a last resort, try inlining function</p>
<div id="seo_alrp_related"><h2>Posts Related to How to optimize php code.</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-mysql-query-and-mysql-database/" rel="bookmark">How to optimize mysql query and mysql database?</a></h3><p>There is lots of way to optimize mysql. once you optimize your query and database of mysql it will make your website and application very ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-make-controller-without-a-model-in-cakephp/" rel="bookmark">How To Make Controller Without a Model in cakephp ?</a></h3><p>class MyController extends AppController {     // var $uses = null; works too     var $uses = array();     function index()     {     } } If you omit the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-company-how-any-programmer-will-feel-secure-in-company/" rel="bookmark">Programmer VS Company : How any programmer will feel secure in Company?</a></h3><p>Programmer VS Company All of friends I am going to share my Experience about the company and Programmer ,what I feel in last 7 Years ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/inserting-multiple-rows-in-cakephp/" rel="bookmark">Inserting Multiple Rows in Cakephp</a></h3><p>I had a situation where I needed to iterate through a list of items and insert new rows for each. I quickly discovered that if ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-table-for-custom-module-in-magento/" rel="bookmark">Using Custom Table for Custom Module in Magento</a></h3><p>If you want to create a custom module in Magento that has something to do with storing data into a custom table and using that ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/09/how-to-optimize-php-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programmer VS Company : How any programmer will feel secure in Company?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-company-how-any-programmer-will-feel-secure-in-company/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-company-how-any-programmer-will-feel-secure-in-company/#comments</comments>
		<pubDate>Fri, 02 Sep 2011 17:27:39 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[humor]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[average minds discuss events]]></category>
		<category><![CDATA[Great minds discuss ideas]]></category>
		<category><![CDATA[How any programmer will feel secure in Company.]]></category>
		<category><![CDATA[How to make good environment.]]></category>
		<category><![CDATA[I have join in company and on the first day I call Sir to some people after some days I realized that person is not my senior they have same experience but I can't call by name So take time to say or ]]></category>
		<category><![CDATA[MOST PROFESSIONAL LINE]]></category>
		<category><![CDATA[Programmer VS Company]]></category>
		<category><![CDATA[small minds discuss about people....!! So what you want to be]]></category>
		<category><![CDATA[What Programmer and Company Think.]]></category>
		<category><![CDATA[What Programmer should do at work place.]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1626</guid>
		<description><![CDATA[Programmer VS Company All of friends I am going to share my Experience about the company and Programmer ,what I feel in last 7 Years and I work at 13 places (What was my position there Trainer, Programmer, Sr. Programmer and finally Team Lead) at some places I do the job on Saturday and Sunday. [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Programmer VS Company</strong></p>
<p>All of friends I am going to share my Experience about the company and Programmer ,what I feel in last 7 Years and I work at 13</p>
<p>places (What was my position there Trainer, Programmer, Sr. Programmer and finally Team Lead) at some places I do the job on Saturday and Sunday.</p>
<p><strong>What Programmer and Company Think.</strong></p>
<p>Every Programmer Think his/her salary is low as per work they are doing but some freshers think when they get the job in company</p>
<p>after showing some fake experience Company is fool but he/she has no idea that the company know about that even some times I take</p>
<p>interview and I know this is fake company but the person who sited front of me is very talented and fast learner. That&#8217;s the reason we entertain.</p>
<p>Every Company always think We are paying more than programmer&#8217;s capability But the company show two different strategy First they will realized you to you are getting good salary here and you are the most quality programmer and once you reach your one year or 6 month there or when the times comes for increment then the company always try to demoralize you and will try to proof that you are not right person to get increment.and you will get frustrated and start thinking is really I am not good programmer.</p>
<p>But some exceptional company also available they give you more than you expect but when it happens. the case is when the third person is dealing then you get more salary in any company like the boss is not dealing the salary.</p>
<p><strong>What Programmer should do at work place.</strong></p>
<p>In the software company lots of people work so it&#8217;s a natural everybody will have different quality, culture and most is different</p>
<p>Thinking.</p>
<p>Programmers works depend on these three most important categories (quality, culture and Thinking).<br />
If Programmer have good quality then they will do very good job and very good increment and appreciation from boss. If the</p>
<p>programmer quality is not good then they will start freelancing from the company and no doubt freelancing give money but programmer</p>
<p>always feel unsecured because they are doing some wrong with his/her profession.</p>
<p>I have seen most of the programmer do the freelancing at the work place but I felt that instead of doing freelancing at office programmer should concentrate on their work and project. or if you don&#8217;t have much work then you should start learning session to make your professional quality stronger.</p>
<p><strong>How any programmer will feel secure in Company.</strong></p>
<p>If you are good learner and like to study at home then you will feel always secure.This is main mantra to feel secure. Other than there are no any formula will work.</p>
<p><strong>How to make good environment.</strong></p>
<p>Once you join, then take some days for fluent interaction means take time to understand people see I have live example.</p>
<p>&nbsp;</p>
<p>Don&#8217;t Talk personal thing to anybody.<br />
Don&#8217;t talk bad about any people even ignore that people who always talks like that try to avoid politics.<br />
Don&#8217;t make someone special behave same to everybody.<br />
Always try to share your ideas to your boss and project manager Means always Open your mouth Don&#8217;t be Ideal.</p>
<p>In My career one of my best project manager is &#8220;SAHU SIR&#8221; I can&#8217;t disclose the company name. He is always look cool and he always appreciate your work and your honesty.</p>
<p>Most Important Don&#8217;t take quick DECISION in company for the people and JOB.</p>
<p><strong>MOST PROFESSIONAL LINE</strong></p>
<p><em><strong>Great minds discuss ideas,average minds discuss events,small minds discuss about people&#8230;.!! So what you want to be</strong></em></p>
<p>Article By: Bagesh Singh<br />
Email : bageshsingh@gmail.com<br />
Highly COPYRIGHTED</p>
<div id="seo_alrp_related"><h2>Posts Related to Programmer VS Company : How any programmer will feel secure in Company? </h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-tester/" rel="bookmark">Programmer vs Tester</a></h3><p>When Programmer Think about tester they always feel anger. When Tester Think about programmer they Smile. Do you know why because due to tester programmer ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/what-a-good-seo-company-can-do-for-you/" rel="bookmark">What a Good SEO company can do for you?</a></h3><p>There is a continuous rise in the number of people creating their own e commerce sites or online businesses because they know there is good ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/07/outsourcing-web-design-and-development-company/" rel="bookmark">Outsourcing web design and development company</a></h3><p>MPR Group Solutions is an IT company. We have well trained and experienced staff. We have Web Design, Graphic Design, Multimedia Services, Flash Web Design ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/07/guide-to-a-great-press-release/" rel="bookmark">Guide To A Great Press Release</a></h3><p>Press release is a document that allows companies to announce their products and services. It has a similar format like the news. News are shorter ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/need-loans-for-your-it-company/" rel="bookmark">Need loans for your IT Company??</a></h3><p>Do you want to open your own IT company? Is your IT company suffering from financial crisis? Then I would recommend to check EZUnsecured.com . ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/09/programmer-vs-company-how-any-programmer-will-feel-secure-in-company/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CURL PHP: Email this page to a friend</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/08/curl-php-email-this-page-to-a-friend/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/08/curl-php-email-this-page-to-a-friend/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 18:32:29 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[cURL PHP]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Php interview question]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1572</guid>
		<description><![CDATA[Using curl to take snapshots of the current page for emailing the HTML is a clever little idea. (ie: Email this page to a friend) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 &#60;?php //to be explained below! session_write_close(); $pageurl = "http://www.site.com/content.php?PHPSESSID=123XYZ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); [...]]]></description>
			<content:encoded><![CDATA[<p>Using curl to take snapshots of the current page for emailing the HTML is a clever little idea. (ie: Email this page to a friend)</p>
<div>
<div id="highlighter_396792">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
</td>
<td>
<div>
<div><code>&lt;?php</code></div>
<div><code>//to be explained below!</code></div>
<div><code>session_write_close();</code></div>
<div></div>
<div><code>$pageurl</code> <code>= "http:</code><code>//www.site.com/content.php?PHPSESSID=123XYZ</code></div>
<div><code>curl_setopt(</code><code>$ch</code><code>, CURLOPT_RETURNTRANSFER, 1);</code></div>
<div></div>
<div><code>curl_setopt (</code><code>$ch</code><code>, CURLOPT_URL, </code><code>$pageurl</code> <code>);</code></div>
<div><code>$html</code> <code>= curl_exec ( </code><code>$ch</code> <code>);</code></div>
<div><code>curl_close(</code><code>$ch</code><code>);</code></div>
<div></div>
<div><code>//then you need to fix pathing to absolute</code></div>
<div><code>$search</code> <code>= </code><code>"/(src|href|background)="</code><code>[^:,^&gt;,^\</code><code>"]*\"/i"</code><code>;</code></div>
<div></div>
<div><code>preg_match_all ( </code><code>$search</code><code>, </code><code>$html</code><code>, </code><code>$a_matches</code> <code>);</code></div>
<div></div>
<div><code>//you can figure out the rest ! but thought the reg expression is useful as well</code></div>
<div><code>?&gt;</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>But here is the catch, you may want to make sure curl connects to the server under the same session as the browser. So naturally you pass the session cookie through the curl system either by the cookie jar system, or through the query string in the path.</p>
<p>This is where you will get stuck. PHP will need write access to the same session file simultaneously!! causing serious hanging issues!</p>
<p>This is why you should close off your session before you make curl take a page snapshot!</p>
<div id="seo_alrp_related"><h2>Posts Related to CURL PHP: Email this page to a friend </h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/05/php-curl-functions-list/" rel="bookmark">PHP Curl Functions List</a></h3><p>curl_close — Close a CURL session curl_errno — Return an integer containing the last error number curl_error — Return a string containing the last error ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/curl-urls-with-a-get-variable/" rel="bookmark">CURL URLS with a get variable</a></h3><p>I had the following experience when harvesting urls with a get variable from a page using cUrl. HTML pages will output ampersands as &amp;amp when ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/curl-php-trouble-on-server-2003-iis-6-php_curl/" rel="bookmark">CURL PHP : Trouble on server 2003, IIS 6 php_curl</a></h3><p>run (as an administrator) php.exe -i &gt; C:\phpinfo.txt and go open C:\phpinfo.txt, look in the file to see if CURL was loading, if it’s there ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/03/how-to-do-file-uploading-using-php-curl/" rel="bookmark">how to do File Uploading Using PHP Curl</a></h3><p>File uploading through PHP Curl is very simple. You just have to append @ in front of path of file name &amp; send it to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-get-the-current-page-url/" rel="bookmark">How to Get the Current Page URL</a></h3><p>Sometimes, you might want to get the current page URL that is shown in the browser URL window. For example if you want to let ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/08/curl-php-email-this-page-to-a-friend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Canada’s postal code validation in PHP</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/08/canada%e2%80%99s-postal-code-validation-in-php/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/08/canada%e2%80%99s-postal-code-validation-in-php/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 17:47:45 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Php interview question]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[canada postal code]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1468</guid>
		<description><![CDATA[Few days back, My friend Narendra asked me how to validate the postal code of Canada which is entered through the text box.And, I came up with this Php function as solution for him. &#160; These are the conditions for validation of the postal code of Canada. There are six alphanumeric letters. Alphabate and digits [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Few days back, My friend Narendra asked me how to validate the postal code of Canada which is entered through the text box.And, I came up with this Php function as solution for him.</p>
<p>&nbsp;</p>
<p align="justify">
<p align="justify">These are the conditions for validation of the postal code of Canada.</p>
<ol>
<li>There are six alphanumeric letters.</li>
<li>Alphabate and digits are alternate and first letter must be alphabate.</li>
<li>The alphabate shouldn’t contain letters “d”,”f”,”i”,”o”,”q” and “u”.</li>
</ol>
<p align="justify">Postal code “<strong>A1B2c5</strong>” is a valid postal code whereas “<strong>A1f2cZ</strong>” or “<strong>1AC2E5</strong>” are invalid postal code of Canada.</p>
<pre>//function to validate postal code of canada
function validateCanadaZip($zip_code)
{
 //function by Roshan Bhattara(http://roshanbh.com.np)
 if(preg_match("/^([a-ceghj-npr-tv-z]){1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}$/i",$zip_code))
    return true;
 else
    return false;
}</pre>
<p align="justify">Now, let’s look at the explanation of the regular expression inside the preg_match() to validate the postal code of Canada as specified by the above condition. As you might know that a Perl compatible regular expression enclosed within “/” sign. The “i” at the end of the expression refers that this comparison is case insensitive.As most of you know, “^”sign is the start of the regular expression and “$” represent the end of the regular expression. And there are three repeated expressions like “([a-ceghj-npr-tv-z]){1}[0-9]{1}”. Let me explain it, the expression “([a-ceghj-npr-tv-z]){1}” represents that there should be one alphabate which doesn’t contain “d”,”f”,”i”,”o”,”q” and “i”. Furthermore, the expression “[0-9]{1}” represents that there should be one digit.</p>
<div id="seo_alrp_related"><h2>Posts Related to Canada’s postal code validation in PHP</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/usa%e2%80%99s-zip-code-validation-in-php/" rel="bookmark">USA’s Zip Code Validation in PHP</a></h3><p>My friend Sushil was trying to write the regular expression for validating the format of the zip code of USA. After spending few minutes, I ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/ip-address-validation-in-php-using-regular-expression/" rel="bookmark">Ip address validation in PHP using regular expression</a></h3><p>If you don’t know how to validate the IP address format in PHP, then you are in the right place.I’ll show you here how to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-do-date-format-validation-in-php/" rel="bookmark">How to do Date format validation in PHP</a></h3><p>Today Sushil asked me how can we validate the date which is entered from textbox in “YYYY-MM-DD” format. Well, we can validate the format of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/05/php-regular-expression-regex-functions-list/" rel="bookmark">PHP Regular Expression (Regex) Functions List</a></h3><p>Perl-Compatible Functions List preg_grep — Return array entries that match the pattern preg_match_all — Perform a global regular expression match preg_match — Perform a regular ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/understanding-and-validating-integers-in-php/" rel="bookmark">Understanding and Validating Integers in PHP</a></h3><p>I’ve found many of my friends struggling with the validation of integers i.e. the numbers with only digits in PHP. Some of them were wondering ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/08/canada%e2%80%99s-postal-code-validation-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>USA’s Zip Code Validation in PHP</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/08/usa%e2%80%99s-zip-code-validation-in-php/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/08/usa%e2%80%99s-zip-code-validation-in-php/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 17:46:47 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Google Android]]></category>
		<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[Php interview question]]></category>
		<category><![CDATA[tips and technique]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1466</guid>
		<description><![CDATA[My friend Sushil was trying to write the regular expression for validating the format of the zip code of USA. After spending few minutes, I came to this solution. &#160; The valid format of zip code of USA might be a five digit number like “12345” or in the format of 4 digit followed by [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">My friend Sushil was trying to write the regular expression for validating the format of the zip code of USA. After spending few minutes, I came to this solution.</p>
<p>&nbsp;</p>
<p align="justify">The valid format of zip code of USA might be a five digit number like “<span style="color: #003366;">12345</span>” or in the format of 4 digit followed by first 5 digits like “<span style="color: #003366;">12345-5434</span>“.And, we need a function to validate the both kind of format of zip code.</p>
<p>Here is the function,</p>
<pre>function validateUSAZip($zip_code)
{
  if(preg_match("/^([0-9]{5})(-[0-9]{4})?$/i",$zip_code))
    return true;
  else
    return false;
}</pre>
<p>Now, let’s look at the explanation of the regular expression used in this function. A perl regular expression always starts with “<span style="color: #003366;">/</span>” and ends with “<span style="color: #003366;">/</span>” and “i” after closing “<span style="color: #003366;">/</span>” refers that the expression is “case insensitive”.As you know, “^” refers that, it is the beginning of the expression. And, the expression “<span style="color: #003366;">([0-9]{5})</span>” tells that there should be exactly 5 digits at the beginning of the expression. Furthermor</p>
<div id="seo_alrp_related"><h2>Posts Related to USA’s Zip Code Validation in PHP</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/ip-address-validation-in-php-using-regular-expression/" rel="bookmark">Ip address validation in PHP using regular expression</a></h3><p>If you don’t know how to validate the IP address format in PHP, then you are in the right place.I’ll show you here how to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/canada%e2%80%99s-postal-code-validation-in-php/" rel="bookmark">Canada’s postal code validation in PHP</a></h3><p>Few days back, My friend Narendra asked me how to validate the postal code of Canada which is entered through the text box.And, I came ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-do-date-format-validation-in-php/" rel="bookmark">How to do Date format validation in PHP</a></h3><p>Today Sushil asked me how can we validate the date which is entered from textbox in “YYYY-MM-DD” format. Well, we can validate the format of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/05/php-regular-expression-regex-functions-list/" rel="bookmark">PHP Regular Expression (Regex) Functions List</a></h3><p>Perl-Compatible Functions List preg_grep — Return array entries that match the pattern preg_match_all — Perform a global regular expression match preg_match — Perform a regular ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/understanding-and-validating-integers-in-php/" rel="bookmark">Understanding and Validating Integers in PHP</a></h3><p>I’ve found many of my friends struggling with the validation of integers i.e. the numbers with only digits in PHP. Some of them were wondering ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/08/usa%e2%80%99s-zip-code-validation-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Textbox to accept only numbers (digits) using jquery</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2011/08/textbox-to-accept-only-numbers-digits-using-jquery-2/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2011/08/textbox-to-accept-only-numbers-digits-using-jquery-2/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 17:45:47 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[Interview Question]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[JQuery Interview Questions]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=1464</guid>
		<description><![CDATA[Few days back, my friend Parleen asked me how can we make a textbox which just accepts only numbers specially digits only. And, for his I come up with this solution of textbox which only accepts digits, and if you try to enter any alpha bates in it then it displays the error message with [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">Few days back, my friend Parleen asked me how can we make a textbox which just accepts only numbers specially digits only. And, for his I come up with this solution of textbox which only accepts digits, and if you try to enter any alpha bates in it then it displays the error message with animation.</p>
<p>&nbsp;</p>
<p align="justify"><strong>View Demo </strong></p>
<p align="justify"><strong>HTML Code </strong></p>
<pre>&lt;input type="text" name="quantity" id="quantity" /&gt; &lt;span id="errmsg"&gt;&lt;/span&gt;</pre>
<p align="justify">As you can see above, I’ve given the name and id of textbox to “quantity” in this example.This is the textbox which only accepts numbers (digits only). You can see “span” after textbox which is used to display the error message with fading effect using jQuery.</p>
<p align="justify"><strong>Javascript Code </strong></p>
<p align="justify">First of all, we need to use jQuery library as we’re using the jquery’s function to accept only digits.</p>
<pre>&lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;</pre>
<p align="justify">Now le’ts write the code in JavaScript using jQuery to accept only digits in textbox and displaying error with animation.</p>
<pre>//when key is pressed in the textbox$("#quantity").keypress(function (e)
{
  //if the letter is not digit then display error and don't type anything
  if( e.which!=8 &amp;&amp; e.which!=0 &amp;&amp; (e.which&lt;48 || e.which&gt;57))
  {
    //display error message
    $("#errmsg").html("Digits Only").show().fadeOut("slow");
    return false;
  }
});</pre>
<p align="justify">When the key is pressed, we’re using the key’s ASCII value to check which button is pressed. In first expression, delete, tab or backspace button is is checked and “8″ is the ASCII values of the Back-space. Digits are checked in the second expression. “48″ is the ASCII values of “0″ and “57″ is the ASCII values of “9″. The the ASCII values of the other digits lies between “48″ to “57″. And, if the key pressed values doesn’t lies withing these range, then we are displaying the error message with jQuery’s fading effect.</p>
<p align="justify">And, the “return false” statement means that this functions returns false values which means not to type anything on the text box.</p>
<p align="justify"><strong><a href="http://roshanbh.com.np/codes/accept-only-digit.zip" target="_blank">Download Full Source Code</a> </strong></p>
<div id="seo_alrp_related"><h2>Posts Related to Textbox to accept only numbers (digits) using jquery</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/textbox-to-accept-only-numbers-digits-using-jquery/" rel="bookmark">Textbox to accept only numbers (digits) using jquery</a></h3><p>Few days back, my friend Parleen asked me how can we make a textbox which just accepts only numbers specially digits only. And, for his ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/understanding-and-validating-integers-in-php/" rel="bookmark">Understanding and Validating Integers in PHP</a></h3><p>I’ve found many of my friends struggling with the validation of integers i.e. the numbers with only digits in PHP. Some of them were wondering ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/ip-address-validation-in-php-using-regular-expression/" rel="bookmark">Ip address validation in PHP using regular expression</a></h3><p>If you don’t know how to validate the IP address format in PHP, then you are in the right place.I’ll show you here how to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/02/get-and-set-form-element-values-using-jquery/" rel="bookmark">Get and Set Form Element Values using jQuery</a></h3><p>One of the most frequently asked questions about jQuery is to Get or Set values of HTML Form elements. The jQuery val() method lets you ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2011/08/textbox-to-accept-only-numbers-digits-using-jquery-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

