<?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; query</title>
	<atom:link href="http://www.bageshsingh.com/bagesh-blog/tag/query/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>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 17:12:05 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Home]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[Others]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=828</guid>
		<description><![CDATA[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 person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP [...]]]></description>
			<content:encoded><![CDATA[<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 person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access from a PHP file was creating the overhead to the CPU of the server.</p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p>We’re working on a website which was similar to http://www.swoopo.co.uk/ and as you can see clearly in that website the most recent data should be fetched form MySql database in each second. in the PHP page, which was being called from Ajax every second, had around 5 SQL queries to retrieve data from server.</p>
<p>First of all, I optimized that page reducing the 5 queries into single query by using left outer joins among 3 tables. And then, I did benchmark test by using Apache benchmark tool(ab) 50 request with concurrency of 50 with the following command.</p>
<blockquote><p>ab -n 50 -c 50 http://xyz.com/ajax_page.php</p></blockquote>
<p>And then in another SSH shell prompt, I run the top command to view the CPU usages parallelly.</p>
<p>I was still horrified that the CPU usages by mysql after 50 concurrent user was going out of control(100%) despite of optimized query. But many joins have been used in that single query and lots of data were there in those tables so the database overhead was high even though it was a single query.</p>
<h4>How did I reduced the CPU overload drastically caused by MySql?</h4>
<p>Now, the first challenge was to reduce the database access. It was clear that it was caused by concurrent database overhead in the PHP page which was being called in every second. Here is the simple steps what I did to reduce the database overhead.</p>
<ol>
<li>I created another PHP file in which I’ve transferred the mysql query causing CPU overhead and called it from Cronjob.</li>
<li>Created a temporary table for storing the output given by  PHP page called from CronJob.</li>
<li>Then, I scheduled the CronJob in every second, don’t tell me that CronJob can’t be run less than a minute, take a look at this post before saying this.And from each call, the output data was stored in the temporary table.</li>
<li>And, finally from the Ajax the a new PHP page was called which was only accessing the data from temporary table with single row.</li>
</ol>
<p>I did the same benchmarking again to the newly made page(which is accessing data only from temporary table) and saw that CPU usages after the this process reduced drastically.</p>
<p>I know I can further reduce the CPU overhead by storing the temporary data in a text file. You guyz know that I’m lazy so that part is left for another day.</p>
<div id="seo_alrp_related"><h2>Posts Related to How did I reduce CPU overhead problem caused by MySql?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</p></div></li><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/05/mysql-and-sql-injection/" rel="bookmark">MySQL and SQL Injection</a></h3><p>If you take user input through a webpage and insert it into a MySQL database there's a chance that you have left yourself wide open ...</p></div></li><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></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/11/reduce-cpu-overhead-problem-by-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get Query as a String in Magento?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 13:37:09 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHP Third Party Tools]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=447</guid>
		<description><![CDATA[Magento as you might know or not! has really a very PIA (Pain in the A**) type of methods to create SQL, execute and fetch! There are two ways of getting SQL from the collection of Magento. Here are the two ways. 1. Only Echoing Query String. For just echoing the query string you must [...]]]></description>
			<content:encoded><![CDATA[<p>Magento as you might know or not! has really a very PIA (Pain in the  A**) type of methods to create SQL, execute and fetch! There are two  ways of getting SQL from the collection of Magento. Here are the two  ways.</p>
<p><strong>1. Only Echoing Query String.</strong><br />
For just echoing the query string you must call printlogquery(), method  the the collection. Like.</p>
<div id="highlighter_578921">
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>/** If $collection is your collection**/</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>$collection</code><code>-&gt;printlogquery(true);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>3</code></td>
<td><code>/** Don't forget to write  true in param**/</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>But by this method you cannot assign the query you get echoed to some  variable. To get the query string here is what you do.</p>
<p><strong>2. Getting the query String</strong></p>
<div id="highlighter_169759">
<div>
<div><a title="view source" href="http://subesh.com.np/2009/11/how-to-get-query-as-a-string-in-magento/#viewSource"></a></p>
<div><embed id="highlighter_169759_clipboard" title="copy to clipboard" type="application/x-shockwave-flash" width="16" height="16" src="http://subesh.com.np/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/clipboard.swf" allowscriptaccess="always" wmode="transparent" flashvars="highlighterId=highlighter_169759" menu="false"></embed></div>
</div>
</div>
<div>
<div>
<table>
<tbody>
<tr>
<td><code>1</code></td>
<td><code>$query</code><code>=</code><code>$collection</code><code>-&gt;getSelectSql(true);</code></td>
</tr>
</tbody>
</table>
</div>
<div>
<table>
<tbody>
<tr>
<td><code>2</code></td>
<td><code>echo</code> <code>$query</code><code>;</code></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<p>You can then use this $query to concat with more query, in some cases  you desperately need this.</p>
<p>Stay Tuned!</p>
<div id="seo_alrp_related"><h2>Posts Related to How to get Query as a String in Magento?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/" rel="bookmark">Using Custom Query in Magento</a></h3><p>Magento has given us very good features to manage Models and Collection for interacting with Database tables. Nowonder, they are very helpful in most of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/" rel="bookmark">Creating Collection of Objects in Magento using a</a></h3><p>Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2011/08/how-to-make-dsn-and-dsn-less-connections/" rel="bookmark">How to make DSN and DSN-less connections</a></h3><p>DSN stands for 'Data Source Name'. It is an easy way to assign useful and easily rememberable names to data sources which may not be ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/06/how-cross-site-scripting-xss-browser-attacks/" rel="bookmark">How Cross Site Scripting XSS browser attacks</a></h3><p>Now a days Web applications are becoming more and more dynamic. Dynamic websites means contents shown on web page are pulled dynamically depending on some ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Custom Query in Magento</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento-2/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento-2/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 13:26:35 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHP Third Party Tools]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=434</guid>
		<description><![CDATA[Magento has given us very good features to manage Models and Collection for interacting with Database tables. Nowonder, they are very helpful in most of the cases. Yet, we may need to write custom query in some cases (if you need it quick or if you are new to Models &#38; Collection in Magento). But [...]]]></description>
			<content:encoded><![CDATA[<p>Magento has given us very good features to manage Models and  Collection for interacting with Database tables. Nowonder, they are very  helpful in most of the cases. Yet, we may need to write custom query in  some cases (if you need it quick or if you are new to Models &amp;  Collection in Magento). But by Magento</p>
<div id="seo_alrp_related"><h2>Posts Related to Using Custom Query in Magento</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/" rel="bookmark">Creating Collection of Objects in Magento using a</a></h3><p>Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/" rel="bookmark">How to get Query as a String in Magento?</a></h3><p>Magento as you might know or not! has really a very PIA (Pain in the A**) type of methods to create SQL, execute and fetch! ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/10/retrieve-products-with-a-specific-attribute-value-in-magento/" rel="bookmark">Retrieve products with a specific attribute value in magento</a></h3><p>Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model. To instantiate a Product collection, ...</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><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/adding-custom-options-to-a-product-in-magento/" rel="bookmark">Adding custom options to a product in Magento</a></h3><p>Adding custom option in Magento is pretty easy! You just need to know the format of an array, which is taken by catalog/product_option Model to ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Custom Query in Magento</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 13:25:39 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[PHP Third Party Tools]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=432</guid>
		<description><![CDATA[Magento has given us very good features to manage Models and Collection for interacting with Database tables. Nowonder, they are very helpful in most of the cases. Yet, we may need to write custom query in some cases (if you need it quick or if you are new to Models &#38; Collection in Magento). But [...]]]></description>
			<content:encoded><![CDATA[<p>Magento has given us very good features to manage Models and  Collection for interacting with Database tables. Nowonder, they are very  helpful in most of the cases. Yet, we may need to write custom query in  some cases (if you need it quick or if you are new to Models &amp;  Collection in Magento). But by Magento</p>
<div id="seo_alrp_related"><h2>Posts Related to Using Custom Query in Magento</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/" rel="bookmark">Creating Collection of Objects in Magento using a</a></h3><p>Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/" rel="bookmark">How to get Query as a String in Magento?</a></h3><p>Magento as you might know or not! has really a very PIA (Pain in the A**) type of methods to create SQL, execute and fetch! ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/10/retrieve-products-with-a-specific-attribute-value-in-magento/" rel="bookmark">Retrieve products with a specific attribute value in magento</a></h3><p>Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model. To instantiate a Product collection, ...</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><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/adding-custom-options-to-a-product-in-magento/" rel="bookmark">Adding custom options to a product in Magento</a></h3><p>Adding custom option in Magento is pretty easy! You just need to know the format of an array, which is taken by catalog/product_option Model to ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redirect to some other location from Model or Observer in Magento</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/redirect-to-some-other-location-from-model-or-observer-in-magento/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/redirect-to-some-other-location-from-model-or-observer-in-magento/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:46:20 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[Controllers]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=407</guid>
		<description><![CDATA[Redirection in Magento Posts Related to Redirect to some other location from Model or Observer in MagentoCreating Collection of Objects in Magento using aHave you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important ...Adding custom options to a product in [...]]]></description>
			<content:encoded><![CDATA[<p>Redirection in Magento</p>
<div id="seo_alrp_related"><h2>Posts Related to Redirect to some other location from Model or Observer in Magento</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/" rel="bookmark">Creating Collection of Objects in Magento using a</a></h3><p>Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/adding-custom-options-to-a-product-in-magento/" rel="bookmark">Adding custom options to a product in Magento</a></h3><p>Adding custom option in Magento is pretty easy! You just need to know the format of an array, which is taken by catalog/product_option Model to ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/" rel="bookmark">Using Custom Query in Magento</a></h3><p>Magento has given us very good features to manage Models and Collection for interacting with Database tables. Nowonder, they are very helpful in most of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/general-workflow-of-magento%e2%80%99s-importexport-%e2%80%93-dataflow/" rel="bookmark">General Workflow of Magento</a></h3><p>Magento</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/redirect-to-some-other-location-from-model-or-observer-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Product Links in Magento Using Custom Query</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/creating-product-links-in-magento-using-custom-query/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/creating-product-links-in-magento-using-custom-query/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:42:31 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[Import]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/2010/04/creating-product-links-in-magento-using-custom-query/</guid>
		<description><![CDATA[I’ve already made a post in this blog about Adding Related Product and other links to Product in Magento . But when I used the method to creating links among product’s, while importing very large number of products and creating large number of product links, it took a lot of time and resource. So I [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve already made a post in this blog about Adding Related Product and other links to Product in Magento . But when I used the method to creating links among product’s, while importing very large number of products and creating large number of product links, it took a lot of time and resource. So I thought why not give it a try by direclty creating a link using SQL? And YES! it worked.</p>
<p>&nbsp;</p>
<p>Below is the code how I created those links using Custom SQL. But I have to tell you that the former methods looks organized, this is just a work around to a situation. You might know what I am trying to say!</p>
<div>?</div>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>01</div>
<div>02</div>
<div>03</div>
<div>04</div>
<div>05</div>
<div>06</div>
<div>07</div>
<div>08</div>
<div>09</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>
<div>19</div>
<div>20</div>
<div>21</div>
<div>22</div>
<div>23</div>
<div>24</div>
<div>25</div>
<div>26</div>
<div>27</div>
</td>
<td>
<div>
<div><code>$resource</code>   <code>= Mage :: getSingleton( </code><code>'core/resource'</code> <code>);</code></div>
<div><code>$read</code><code>= </code><code>$resource</code> <code>-&gt; getConnection( </code><code>'core_read'</code> <code>);</code></div>
<div><code>$write</code><code>= </code><code>$resource</code><code>-&gt;getConnection(</code><code>'core_write'</code><code>);</code></div>
<div><code>$linkTable</code><code>=</code><code>$resource</code><code>-&gt;getTableName(</code><code>'catalog/product_link'</code><code>);</code></div>
<div></div>
<div><code>// Creating Upsell Product link</code></div>
<div></div>
<div><code>$write</code><code>-&gt;query("INSERT into </code><code>$linkTable</code> <code>SET</code></div>
<div><code>                            </code><code>product_id=</code><code>'".$productId."'</code><code>,</code></div>
<div><code>                            </code><code>linked_product_id=</code><code>'".$linkProduct."'</code><code>,</code></div>
<div><code>                            </code><code>link_type_id=</code><code>'".Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL."'</code></div>
<div><code>            </code><code>");</code></div>
<div></div>
<div><code>// Creating Related Product link</code></div>
<div></div>
<div><code>$write</code><code>-&gt;query("INSERT into </code><code>$linkTable</code> <code>SET</code></div>
<div><code>                            </code><code>product_id=</code><code>'".$productId."'</code><code>,</code></div>
<div><code>                            </code><code>linked_product_id=</code><code>'".$linkProduct."'</code><code>,</code></div>
<div><code>                            </code><code>link_type_id=</code><code>'".Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED."'</code></div>
<div><code>            </code><code>");</code></div>
<div></div>
<div><code>// Creating Crosssell Product Link</code></div>
<div><code>$write</code><code>-&gt;query("INSERT into </code><code>$linkTable</code> <code>SET</code></div>
<div><code>                            </code><code>product_id=</code><code>'".$productId."'</code><code>,</code></div>
<div><code>                            </code><code>linked_product_id=</code><code>'".$linkProduct."'</code><code>,</code></div>
<div><code>                            </code><code>link_type_id=</code><code>'".Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL."'</code></div>
<div><code>            </code><code>");</code></div>
</div>
</td>
</tr>
</tbody>
</table>
<div id="seo_alrp_related"><h2>Posts Related to Creating Product Links in Magento Using Custom Query</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/adding-related-product-and-other-links-to-product-in-magento/" rel="bookmark">Adding Related Product and other links to Product in Magento</a></h3><p>Here is a simple way of adding product link such as Related, Upsell and Crosssell Link to a product in Magento. I just got the ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/creating-custom-sourced-multiselect-product-attribute/" rel="bookmark">Creating Custom Sourced Multiselect Product Attribute</a></h3><p>Creating Multiselect type of product attribute whose source will be the Magento</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/getting-all-custom-options-of-a-product-in-magento/" rel="bookmark">Getting all custom options of a product in Magento</a></h3><p>Custom options are the options that can be added to any product, which gives an option for the user of the site to select what ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/10/retrieve-products-with-a-specific-attribute-value-in-magento/" rel="bookmark">Retrieve products with a specific attribute value in magento</a></h3><p>Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model. To instantiate a Product collection, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/adding-custom-options-to-a-product-in-magento/" rel="bookmark">Adding custom options to a product in Magento</a></h3><p>Adding custom option in Magento is pretty easy! You just need to know the format of an array, which is taken by catalog/product_option Model to ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/creating-product-links-in-magento-using-custom-query/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Collection of Objects in Magento using a</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:41:29 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=400</guid>
		<description><![CDATA[Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important data structure (if I am right) used in Magento. Most of the queries in Magento will result into collection, and then you will apply a foreach loop to access individual [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how Collection in Magento are built,  containing array of individual Entity Objects of Magento? Collections  are one of the most important data structure (if I am right) used in  Magento. Most of the queries in Magento will result into collection, and  then you will apply a foreach loop to access individual Entity Objects  and their values. Today I came into a different situation where I had  individual objects but needed to create a collection of those objects,  so that I could return the collection from a function.</p>
<p>I have not drilled down to the details of collection, untill today  when I really need it! Do you think its very late? because I have been  into Magento for more than a year now!. Better late than never! So, I  got the way of working out my situation. Here is how I created a  collection from Magento</p>
<div id="seo_alrp_related"><h2>Posts Related to Creating Collection of Objects in Magento using a </h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/10/retrieve-products-with-a-specific-attribute-value-in-magento/" rel="bookmark">Retrieve products with a specific attribute value in magento</a></h3><p>Almost all Magento Models have a corresponding Collection object that can be used to fetch multiple instances of a Model. To instantiate a Product collection, ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/" rel="bookmark">Using Custom Query in Magento</a></h3><p>Magento has given us very good features to manage Models and Collection for interacting with Database tables. Nowonder, they are very helpful in most of ...</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><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/" rel="bookmark">How to get Query as a String in Magento?</a></h3><p>Magento as you might know or not! has really a very PIA (Pain in the A**) type of methods to create SQL, execute and fetch! ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Ordered Items and their Detail from Order ID in Magento</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/getting-ordered-items-and-their-detail-from-order-id-in-magento/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/getting-ordered-items-and-their-detail-from-order-id-in-magento/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:40:41 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=398</guid>
		<description><![CDATA[Here is a small snippet of code, yet useful, to get ordered items and its details. I Posts Related to Getting Ordered Items and their Detail from Order ID in MagentoWhat are section, categories and content items in joomla ?Joomla! is a content management system. Sections and categories allow you to organize your content. The [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small snippet of code, yet useful, to get ordered items and  its details. I</p>
<div id="seo_alrp_related"><h2>Posts Related to Getting Ordered Items and their Detail from Order ID in Magento</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/05/what-are-section-categories-and-content-items-in-joomla/" rel="bookmark">What are section, categories and content items in joomla ?</a></h3><p>Joomla! is a content management system. Sections and categories allow you to organize your content. The basic structure is: Sections include Categories. Categories include content ...</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/05/analysis-usage-of-collections-in-magento/" rel="bookmark">Analysis &#038; Usage of Collections in Magento</a></h3><p>As a Magento Programmer I am fascinated by the use &amp; simplicity of collection used in Magento. Simplicity, does not really mean being simple (it ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/11/create-a-dynamic-scrolling-content-box-using-ajax/" rel="bookmark">Create a Dynamic Scrolling Content Box Using AJAX</a></h3><p>If you have used Google Reader, then you might have noticed the way Google Reader shows feed items, it loads up few items first when ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/creating-collection-of-objects-in-magento-using-a-%e2%80%9cmagical-class%e2%80%9dvarien_data_collection/" rel="bookmark">Creating Collection of Objects in Magento using a</a></h3><p>Have you ever wondered how Collection in Magento are built, containing array of individual Entity Objects of Magento? Collections are one of the most important ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/getting-ordered-items-and-their-detail-from-order-id-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Customer</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/04/getting-customer%e2%80%99s-info-using-single-query-including-billing-and-shipping-addresses-in-magento/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/04/getting-customer%e2%80%99s-info-using-single-query-including-billing-and-shipping-addresses-in-magento/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 17:37:50 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[how-to]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips and technique]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=392</guid>
		<description><![CDATA[Query in Magento can be quite troublesome, if you are a starter..or non-starter. So I Posts Related to Getting CustomerWorking with AJAX in MagentoAjax in Magento can be pretty troublesome.Because you will need to take controllers and layout into account.And I almost used up a whole day trying ...Using Custom Query in MagentoMagento has given [...]]]></description>
			<content:encoded><![CDATA[<p>Query in Magento can be quite troublesome, if you are a starter..or  non-starter. So I</p>
<div id="seo_alrp_related"><h2>Posts Related to Getting Customer</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/working-with-ajax-in-magento/" rel="bookmark">Working with AJAX in Magento</a></h3><p>Ajax in Magento can be pretty troublesome.Because you will need to take controllers and layout into account.And I almost used up a whole day trying ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/using-custom-query-in-magento/" rel="bookmark">Using Custom Query in Magento</a></h3><p>Magento has given us very good features to manage Models and Collection for interacting with Database tables. Nowonder, they are very helpful in most of ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/04/how-to-get-query-as-a-string-in-magento/" rel="bookmark">How to get Query as a String in Magento?</a></h3><p>Magento as you might know or not! has really a very PIA (Pain in the A**) type of methods to create SQL, execute and fetch! ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/customer-information-manager-cim-api-guide/" rel="bookmark">Customer Information Manager (CIM) API Guide</a></h3><p>The Authorize.Net Customer Information Manager (CIM) allows merchants to create customer profiles that are stored on Authorize.Net's secure servers. By providing quick access to stored ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/04/getting-customer%e2%80%99s-info-using-single-query-including-billing-and-shipping-addresses-in-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How did I reduce CPU overhead problem caused by MySql?</title>
		<link>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/</link>
		<comments>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/#comments</comments>
		<pubDate>Tue, 16 Mar 2010 11:22:51 +0000</pubDate>
		<dc:creator>Bagesh Singh</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.bageshsingh.com/bagesh-blog/?p=213</guid>
		<description><![CDATA[From last day, 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 person who to take charge over the project bring it down to the track. After doing few benchmark test, I came to know that the MySql access [...]]]></description>
			<content:encoded><![CDATA[<p>From last day, 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 person who to take charge over the project bring it down to the  track. After doing few benchmark test, I came to know that the MySql  access from a PHP file was creating the overhead to the CPU of the  server.</p>
<h4>Problem of CPU Overhead with MySql</h4>
<p>Let me explain the problem clearly first,</p>
<p>We</p>
<div id="seo_alrp_related"><h2>Posts Related to How did I reduce CPU overhead problem caused by MySql?</h2><ul><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql/" rel="bookmark">How did I reduce CPU overhead problem caused by MySql?</a></h3><p>From last day, We were having problem with a project which was shut down in the middle due to heavy traffic. As a technical manager, ...</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/2010/02/how-to-solve-the-problem-of-retrieving-same-value-by-ajax-%e2%80%93-browser-cache-problem/" rel="bookmark">How to solve the problem of retrieving same value by Ajax</a></h3><p>You might have faced the problem of the getting same response on the consecutive request to a PHP file from Ajax. Well, what happens when ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/03/solving-floating-point-number-precision-lost-problem-in-php/" rel="bookmark">Solving Floating point number precision lost problem in PHP</a></h3><p>The problem of precision lost in floating point number in PHP haunted me for about 10 minutes yesterday but I quickly figured out the problem ...</p></div></li><li><div class="seo_alrp_rl_content"><h3><a href="http://www.bageshsingh.com/bagesh-blog/2010/02/solving-european-characters-western-charset-problem-with-ajax-and-php/" rel="bookmark">Solving European characters (Western charset) problem with Ajax and PHP</a></h3><p>Today, I would like to tell you how to handle character set problem which occurs during the data fetched from PHP using Ajax mainly on ...</p></div></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.bageshsingh.com/bagesh-blog/2010/03/how-did-i-reduce-cpu-overhead-problem-caused-by-mysql-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

