<?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>Prattski &#124; Magento &#38; Web Development &#187; MySQL</title>
	<atom:link href="http://prattski.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://prattski.com</link>
	<description></description>
	<lastBuildDate>Fri, 11 May 2012 14:05:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Magento: Modify Collection To Include Comma Separated Values From Another Table</title>
		<link>http://prattski.com/2011/09/22/magento-modify-collection-to-include-comma-separated-values-from-another-table/</link>
		<comments>http://prattski.com/2011/09/22/magento-modify-collection-to-include-comma-separated-values-from-another-table/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 19:52:19 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://prattski.com/?p=796</guid>
		<description><![CDATA[It was rather difficult to come up with a title for this post, so I&#8217;m not sure that it is completely accurate. But, I have been working on a module, and I needed to modify the catalog/product collection to add &#8230; <a href="http://prattski.com/2011/09/22/magento-modify-collection-to-include-comma-separated-values-from-another-table/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It was rather difficult to come up with a title for this post, so I&#8217;m not sure that it is completely accurate.  But, I have been working on a module, and I needed to modify the catalog/product collection to add a column that contains comma separated skus of the related products associated to each product.</p>
<p>First step is to get the product collection,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$collection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog/product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now we need to modify the collection to add a new select column.  The mysql is also important here.  You&#8217;ll see that I&#8217;m using <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat">GROUP_CONCAT</a> and <a href="http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html">DISTINCT</a>, and towards the bottom specifying to group by &#8216;e.entity_id&#8217;.  I&#8217;m not going to dive into why this is necessary or how it all works. You&#8217;ll be better off visiting the mysql documentation on those.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$collection</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog/product'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$collection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSelect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">columns</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GROUP_CONCAT(DISTINCT (SELECT sku FROM catalog_product_entity WHERE entity_id = r.linked_product_id) SEPARATOR \', \') AS related_skus'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">joinLeft</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'r'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'catalog_product_link'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r.product_id = e.entity_id AND r.link_type_id = 1'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">group</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'e.entity_id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The result of this is an additional field in the collection called &#8216;related_skus&#8217; that is a comma-space separated list of skus that are related products for each product in the collection.</p>
<p>If you want to log the actual query that is generated by this, simply add this line below the code above:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #990000;">log</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$collection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSelect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Hopefully this helps you in some way!</p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2011/09/22/magento-modify-collection-to-include-comma-separated-values-from-another-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Mass Exclude/Unexclude Images</title>
		<link>http://prattski.com/2011/04/11/magento-mass-excludeunexclude-images/</link>
		<comments>http://prattski.com/2011/04/11/magento-mass-excludeunexclude-images/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 13:58:13 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://prattski.com/?p=712</guid>
		<description><![CDATA[By default, Magento will check the &#8216;Exclude&#8217; box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view. Should you ever want to mass unexclude them (or &#8230; <a href="http://prattski.com/2011/04/11/magento-mass-excludeunexclude-images/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>By default, Magento will check the &#8216;Exclude&#8217; box for you on all imported images, making them not show up as a thumbnail under the main product image on the product view.  Should you ever want to mass unexclude them (or mass exclude your images), you can simply run one of the following sql commands in your database:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"># Mass Unexclude
<span style="color: #993333; font-weight: bold;">UPDATE</span><span style="color: #ff0000;">`catalog_product_entity_media_gallery_value`</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #ff0000;">`disabled`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'0'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`disabled`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'1'</span>;
&nbsp;
# Mass Exclude
<span style="color: #993333; font-weight: bold;">UPDATE</span><span style="color: #ff0000;">`catalog_product_entity_media_gallery_value`</span> <span style="color: #993333; font-weight: bold;">SET</span> <span style="color: #ff0000;">`disabled`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'1'</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #ff0000;">`disabled`</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'0'</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2011/04/11/magento-mass-excludeunexclude-images/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mysql: Duplicate a Database</title>
		<link>http://prattski.com/2010/08/06/mysql-duplicate-a-database/</link>
		<comments>http://prattski.com/2010/08/06/mysql-duplicate-a-database/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 03:59:38 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://prattski.com/?p=509</guid>
		<description><![CDATA[I needed to duplicate one of my mysql magento databases today. Instead of dumping it to my computer, then sending it back into a different database, I figured there&#8217;s got to be a more efficient way to do it. Fortunately &#8230; <a href="http://prattski.com/2010/08/06/mysql-duplicate-a-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I needed to duplicate one of my mysql magento databases today.  Instead of dumping it to my computer, then sending it back into a different database, I figured there&#8217;s got to be a more efficient way to do it.  Fortunately there is.  Create the database, then run this from your command line:</p>
<p><code>mysqldump -u [user] --password=[password] databasetodupe | mysql -u [user] --password=[password] newdatabase</code></p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2010/08/06/mysql-duplicate-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento Install: Mysql Error &#8211; SQLSTATE[HY000] [2002] No such file or directory</title>
		<link>http://prattski.com/2010/08/05/magento-install-mysql-error-sqlstatehy000-2002-no-such-file-or-directory/</link>
		<comments>http://prattski.com/2010/08/05/magento-install-mysql-error-sqlstatehy000-2002-no-such-file-or-directory/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 02:45:27 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://prattski.com/?p=500</guid>
		<description><![CDATA[I recently changed up the configuration of my Mac (running 10.6.4) and I was installing a fresh copy of Magento (1.4.1.1) when I ran into the following error when I got to the database credentials: SQLSTATE[HY000] [2002] No such file &#8230; <a href="http://prattski.com/2010/08/05/magento-install-mysql-error-sqlstatehy000-2002-no-such-file-or-directory/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently changed up the configuration of my Mac (running 10.6.4) and I was installing a fresh copy of Magento (1.4.1.1) when I ran into the following error when I got to the database credentials: SQLSTATE[HY000] [2002] No such file or directory.</p>
<p>I did some Googling around and came across someone that seemed to have a <a href="http://echonull.colinta.com/?p=24">similar issue</a>, though not with Magento.  So I figured I&#8217;d give it a shot.  Well, it worked.  The unfortunate part is that, being not all too familiar with how all this configuration stuff works, I don&#8217;t know why it works (if you know why, please let me know).</p>
<h3>The Solution</h3>
<p>Open up your php.ini file (mine was in /etc/).  Look for the following line:</p>
<pre>pdo_mysql.default_socket=/var/mysql/mysql.sock</pre>
<p>If that line exists for you, try changing it to:</p>
<pre>pdo_mysql.default_socket=/tmp/mysql.sock</pre>
<p>Restart apache after saving, and that&#8217;s all I had to do.  One thing to keep in mind though is that I am using the stock php (with 10.6), and I&#8217;m using mysql installed with homebrew.</p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2010/08/05/magento-install-mysql-error-sqlstatehy000-2002-no-such-file-or-directory/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Magento: SQL to Find Missing Images</title>
		<link>http://prattski.com/2010/06/29/magento-sql-to-find-missing-images/</link>
		<comments>http://prattski.com/2010/06/29/magento-sql-to-find-missing-images/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 19:55:21 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://prattski.com/?p=442</guid>
		<description><![CDATA[I just imported a ton of products for new website that I&#8217;m working on, and it turns out that the client misnamed a bunch of images, causing Magento to ignore the image import for those ones. I don&#8217;t want to &#8230; <a href="http://prattski.com/2010/06/29/magento-sql-to-find-missing-images/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-60" title="Magento Icon" src="http://devzone.pratthost.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="Magento Icon" width="67" height="67" /></p>
<p>I just imported a ton of products for new website that I&#8217;m working on, and it turns out that the client misnamed a bunch of images, causing Magento to ignore the image import for those ones.  I don&#8217;t want to scour through the website and the CSV (and the client wouldn&#8217;t want to pay us to do that either), so I figured if I could just come up with a list of SKUs for products missing an image, I could hand it off to them so they could correct everything.</p>
<p>This isn&#8217;t foolproof, but it does the job.  This query will give you a list of SKUs where there is no record in the database for that product&#8217;s &#8216;image&#8217; attribute (the main large product image).</p>
<p><code>SELECT `sku` FROM `catalog_product_entity` AS a LEFT JOIN `catalog_product_entity_varchar` AS b ON a.entity_id = b.entity_id AND b.attribute_id = 74 WHERE b.entity_id IS NULL</code></p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2010/06/29/magento-sql-to-find-missing-images/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mysql: USING BTREE &#8211; Error when dumping from 5.1 and importing to 5.0</title>
		<link>http://prattski.com/2010/06/01/mysql-using-btree-error-when-dumping-from-5-1-and-importing-to-5-0/</link>
		<comments>http://prattski.com/2010/06/01/mysql-using-btree-error-when-dumping-from-5-1-and-importing-to-5-0/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 19:35:30 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=417</guid>
		<description><![CDATA[I was dumping a database today to put onto a different server. I am currently running 5.1.45 locally, and the server I am moving to has 5.0.58. When trying to import the database to the new server, I was getting &#8230; <a href="http://prattski.com/2010/06/01/mysql-using-btree-error-when-dumping-from-5-1-and-importing-to-5-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://prattski.com/wp-content/uploads/2008/09/terminal_icon.jpg" alt="" title="Terminal Icon" width="90" height="90" class="alignleft size-full wp-image-49" /></p>
<p>I was dumping a database today to put onto a different server.  I am currently running 5.1.45 locally, and the server I am moving to has 5.0.58.  When trying to import the database to the new server, I was getting the following error:</p>
<p><br style="clear: both" /></p>
<p><code>ERROR 1064 (42000) at line 576: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'USING BTREE,<br />
  KEY `FK_ATTRIBUTE_VARCHAR_ENTITY` (`entity_id`),<br />
  KEY `FK_CATALO' at line 9</code></p>
<p>After doing some checking around, I found that the problem was the &#8216;USING BTREE&#8217;.  Mysql 5.0 and lower doesn&#8217;t seem to understand what that is about and will fail.  The solution:  Just remove &#8216;USING BTREE&#8217;, and you&#8217;ll be good to go.</p>
<p>It sounds like versions after mine (5.1.45) have fixed this and omit the &#8216;USING BTREE&#8217; from the dumps.</p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2010/06/01/mysql-using-btree-error-when-dumping-from-5-1-and-importing-to-5-0/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>MySQL &amp; PHP: Convert Strings From All Uppercase to Uppercase Only First Letter of Each Word</title>
		<link>http://prattski.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/</link>
		<comments>http://prattski.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 21:00:22 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=215</guid>
		<description><![CDATA[I&#8217;m not sure if it is possible to make that title much shorter than that&#8230; Anyway, I had some old data that I imported to an installation of Magento. All of the product titles were all uppercase, which was quite &#8230; <a href="http://prattski.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://prattski.com/wp-content/uploads/2008/09/php_icon.jpg" alt="" title="PHP Icon" width="82" height="82" class="alignleft size-medium wp-image-65" /></p>
<p>I&#8217;m not sure if it is possible to make that title much shorter than that&#8230;  Anyway, I had some old data that I imported to an installation of Magento.  All of the product titles were all uppercase, which was quite ugly.  I needed a way to convert all of those values to only have uppercase first letter of each word.</p>
<p>Programming that was quite easy, but I noticed that there were also some parts of the string which were not converted like &#8220;On/off&#8221;, &#8220;D.e.&#8221;, &#8220;Quick-connect&#8221;, etc.  The <a href="http://us.php.net/ucfirst">ucwords()</a> function doesn&#8217;t recognize that kind of stuff.  So, I had to find a way around those.  I created an array that houses whatever characters you&#8217;d like to capitalize after (as long as there is a letter immediately after it).  So, those three examples become &#8220;On/Off&#8221;, &#8220;D.E.&#8221;, and &#8220;Quick-Connect&#8221;.</p>
<p>Here&#8217;s what I came up with.  Feel free to use it if you wish &#8211; you&#8217;ll just have to change the database credentials, change the SELECT and UPDATE queries to suit your needs, and edit the $also_after array to uppercase after any characters you want:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Database Connection</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// What Ever Query You Want</span>
<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT value_id, value FROM catalog_product_entity_varchar WHERE attribute_id = 45&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Run For Each Result</span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$value_id</span> 	<span style="color: #339933;">=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value_id</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$value</span>		<span style="color: #339933;">=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">value</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Populate this array with characters that you want this script to capitalize after.</span>
	<span style="color: #666666; font-style: italic;">// If in the string there is &quot;onn/off&quot;, put the &quot;/&quot; character in the array to make &quot;On/Off&quot;</span>
	<span style="color: #666666; font-style: italic;">// otherwise, it would only do &quot;On/off&quot;.</span>
	<span style="color: #000088;">$also_after</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'-'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'('</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Run this function for each value. Returns new string.</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> convert_to_uc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$also_after</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Escape characters for database entry</span>
	<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">real_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Update the database with your new string</span>
	<span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;UPDATE catalog_product_entity_varchar SET value = '<span style="color: #006699; font-weight: bold;">$string</span>' WHERE value_id = '<span style="color: #006699; font-weight: bold;">$value_id</span>'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Convert To Uppercase function</span>
<span style="color: #000000; font-weight: bold;">function</span> convert_to_uc<span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$also_after</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$string</span> 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Convert thet string to all lowercase, then uppercase the first letter of every word.</span>
	<span style="color: #000088;">$string</span> 	<span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// For each $also_after character, run the uc_match function</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$also_after</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace_callback</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(\\'</span><span style="color: #339933;">.</span><span style="color: #000088;">$char</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')(\w)/'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;uc_match&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Returns new formatted string</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Uppercase Match function - used by preg_replace_callback above</span>
<span style="color: #000000; font-weight: bold;">function</span> uc_match<span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento: Easily and Quickly Delete All Products</title>
		<link>http://prattski.com/2008/09/25/magento-easily-and-quickly-delete-all-products/</link>
		<comments>http://prattski.com/2008/09/25/magento-easily-and-quickly-delete-all-products/#comments</comments>
		<pubDate>Thu, 25 Sep 2008 20:10:36 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=75</guid>
		<description><![CDATA[If you have ever tried to delete a large amount of products out of Magento, you&#8217;ll realize that it takes forever, and in many cases, you have to do it in small quantities at a time otherwise it will freeze &#8230; <a href="http://prattski.com/2008/09/25/magento-easily-and-quickly-delete-all-products/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://prattski.com/wp-content/uploads/2008/09/magento_icon.jpg" alt="" title="Magento Icon" width="67" height="67" class="alignleft size-full wp-image-60" /></p>
<p>If you have ever tried to delete a large amount of products out of Magento, you&#8217;ll realize that it takes forever, and in many cases, you have to do it in small quantities at a time otherwise it will freeze up.  I needed to delete all the products out today but found that I could only delete about 30 at a time.  This just wasn&#8217;t going to work since there are about 2500 products in the DB.  I found something out today by accident that turned out to be extremely helpful.</p>
<p>Due to the nature of the InnoDB mysql engine that Magento uses, and the way they setup their foreign keys, all it takes is one simple mysql command, and mysql will automatically clear out all of the product data from all of the different tables it uses.  On top of that, it resets the auto-increment values back to 1 so that you can start off with entity_id 1 again.</p>
<p>I haven&#8217;t given it extensive testing, but I checked every table that I knew that stored product information and they were all clear.  So, if you need to clear out all your products, open up mysql and just enter this one line in:</p>
<p><code>TRUNCATE TABLE `catalog_product_entity`;</code></p>
<p>For more information on how it works, you can visit the <a href="http://dev.mysql.com/doc/refman/5.0/en/truncate.html">Truncate Syntax</a> page on the Mysql website.</p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2008/09/25/magento-easily-and-quickly-delete-all-products/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Mysqli and Object-Oriented PHP</title>
		<link>http://prattski.com/2008/09/22/mysqli-and-object-oriented-php/</link>
		<comments>http://prattski.com/2008/09/22/mysqli-and-object-oriented-php/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 21:36:08 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=62</guid>
		<description><![CDATA[Sometimes it is easy for me to get stuck doing things the way I know how to do it, rather than finding a better, more up-to-date method. I just had a recent post about making multiple connections to mysql, but &#8230; <a href="http://prattski.com/2008/09/22/mysqli-and-object-oriented-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is easy for me to get stuck doing things the way I know how to do it, rather than finding a better, more up-to-date method.  I just had a <a href="http://devzone.pratthost.com/2008/09/15/connecting-to-multiple-mysql-databases-with-php/">recent post</a> about making multiple connections to mysql, but just in the last week, I&#8217;ve learned a better way to do it.  I&#8217;m a little behind in learning this stuff, but I&#8217;m sure there are others out there like me.</p>
<p>Mysqli stands for Mysql Improved.  It came out a while ago, I believe with Mysql 4.1.3 and up.  There are a lot of great benefits to using mysqli, which I won&#8217;t get into now.  Maybe later.  Here&#8217;s just a little to get you started using it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Connect to Database</span>
<span style="color: #000088;">$db</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mysqli<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'host'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'username'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Perform a query</span>
<span style="color: #000088;">$items</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$db</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM cp_items WHERE id &gt; 100&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Run a loop through the results</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$item</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$items</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;ul&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$item</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Connecting to multiple databases at the same time is simple.  Just create a new database object, and call the mysqli functions from it.  You can read the <a href="http://us3.php.net/mysqli">full documentation</a> of everything available with mysqli to learn more about it.</p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2008/09/22/mysqli-and-object-oriented-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turn Off Word Wrap in Leopard Terminal</title>
		<link>http://prattski.com/2008/09/16/turn-off-word-wrap-in-leopard-terminal/</link>
		<comments>http://prattski.com/2008/09/16/turn-off-word-wrap-in-leopard-terminal/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 19:07:30 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=55</guid>
		<description><![CDATA[As I said in the post prior to this, I have really been enjoying using Terminal for accessing MySQL databases. I found a problem with it though. If you have a table with a lot of columns, or a column &#8230; <a href="http://prattski.com/2008/09/16/turn-off-word-wrap-in-leopard-terminal/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://prattski.com/wp-content/uploads/2008/09/terminal_icon.jpg" rel="lightbox[55]"><img src="http://prattski.com/wp-content/uploads/2008/09/terminal_icon.jpg" alt="" title="Terminal Icon" width="90" height="90" class="alignleft size-medium wp-image-49" /></a></p>
<p>As I said in the post prior to this, I have really been enjoying using Terminal for accessing MySQL databases.  I found a problem with it though.  If you have a table with a lot of columns, or a column with a lot of data in it, Terminal will wrap the results of your query making it almost completely unreadable (or a pain to read at best).<br />
<br style="clear: both" /></p>
<div style="width: 300px; margin: 0 auto"><a href="http://prattski.com/wp-content/uploads/2008/09/mysql_wrap.jpg" rel="lightbox[55]"><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/mysql_wrap-300x256.jpg" alt="" title="Mysql Terminal Wrap" width="300" height="256" class="aligncenter size-medium wp-image-56" /></a></div>
<p></p>
<p>I found a work-around.  Though it isn&#8217;t as good as it could be, it does work.  It prevents the wrap, but, everything beyond the right-side of your terminal window is completely removed.  It doesn&#8217;t give you a scroll bar to see beyond, it is literally gone.  If you try to resize your window, you&#8217;ll just get blank space.</p>
<div style="width: 300px; margin: 0 auto"><a href="http://prattski.com/wp-content/uploads/2008/09/mysql_nowrap.jpg" rel="lightbox[55]"><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/mysql_nowrap-300x80.jpg" alt="" title="Mysql Terminal No Wrap" width="300" height="80" class="aligncenter size-medium wp-image-57" /></a></div>
<p></p>
<p>Why Terminal doesn&#8217;t have the ability to turn it on or off is a mystery to me.  But, that said, this fix does have it&#8217;s place, and it is fairly easy to turn on and off.  Here&#8217;s what you do:</p>
<p>Open this file:  $YOURHOME/.bashrc  and place the following in there and save it:</p>
<p><code># Wordwrap off<br />
echo -e "\e[?7l\c"</code></p>
<p>After it is saved, you can close Terminal and re-open it, or restart bash with this command:</p>
<p><code>. ~/.bashrc</code></p>
<p>To turn it off again, just remove or comment out the echo statement you added to .bashrc and restart bash again.</p>
<p>If you have any better suggestions for this, please let me know!  I&#8217;d love to have a better solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://prattski.com/2008/09/16/turn-off-word-wrap-in-leopard-terminal/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

