<?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>Pratthost Developer Zone &#187; MySQL</title>
	<atom:link href="http://devzone.pratthost.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://devzone.pratthost.com</link>
	<description>A resource for web developers</description>
	<lastBuildDate>Tue, 29 Jun 2010 18:47:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Magento: SQL to Find Missing Images</title>
		<link>http://devzone.pratthost.com/2010/06/29/magento-sql-to-find-missing-images/</link>
		<comments>http://devzone.pratthost.com/2010/06/29/magento-sql-to-find-missing-images/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 18:47:11 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=449</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 scour through the website and the CSV (and the client wouldn&#8217;t want to pay us [...]]]></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://devzone.pratthost.com/2010/06/29/magento-sql-to-find-missing-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql: USING BTREE &#8211; Error when dumping from 5.1 and importing to 5.0</title>
		<link>http://devzone.pratthost.com/2010/06/01/mysql-using-btree-error-when-dumping-from-5-1-and-importing-to-5-0/</link>
		<comments>http://devzone.pratthost.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 the following error: ERROR 1064 (42000) at line 576: You have an error in your [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.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://devzone.pratthost.com/2010/06/01/mysql-using-btree-error-when-dumping-from-5-1-and-importing-to-5-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MySQL &amp; PHP: Convert Strings From All Uppercase to Uppercase Only First Letter of Each Word</title>
		<link>http://devzone.pratthost.com/2008/11/04/php-convert-strings-from-all-uppercase-to-uppercase-only-first-letter-of-each-word/</link>
		<comments>http://devzone.pratthost.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 ugly. I needed a way to convert all of those values to only have uppercase [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.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://devzone.pratthost.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://devzone.pratthost.com/2008/09/25/magento-easily-and-quickly-delete-all-products/</link>
		<comments>http://devzone.pratthost.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 up. I needed to delete all the products out today but found that I could [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.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://devzone.pratthost.com/2008/09/25/magento-easily-and-quickly-delete-all-products/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Mysqli and Object-Oriented PHP</title>
		<link>http://devzone.pratthost.com/2008/09/22/mysqli-and-object-oriented-php/</link>
		<comments>http://devzone.pratthost.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 just in the last week, I&#8217;ve learned a better way to do it. I&#8217;m 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://devzone.pratthost.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://devzone.pratthost.com/2008/09/16/turn-off-word-wrap-in-leopard-terminal/</link>
		<comments>http://devzone.pratthost.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 with a lot of data in it, Terminal will wrap the results of your query [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://devzone.pratthost.com/wp-content/uploads/2008/09/terminal_icon.jpg" rel="lightbox[55]"><img src="http://devzone.pratthost.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://devzone.pratthost.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://devzone.pratthost.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://devzone.pratthost.com/2008/09/16/turn-off-word-wrap-in-leopard-terminal/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using MySQL Through The Command Line</title>
		<link>http://devzone.pratthost.com/2008/09/16/using-mysql-through-the-command-line/</link>
		<comments>http://devzone.pratthost.com/2008/09/16/using-mysql-through-the-command-line/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 13:00:48 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=48</guid>
		<description><![CDATA[One of the most popular ways to view and work with a MySQL database is through a web app called phpMyAdmin. There are many other tools out there that you can use, but why use a tool when you&#8217;ve already got a command line to work with? I used to use phpMyAdmin all the time. [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://devzone.pratthost.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>One of the most popular ways to view and work with a MySQL database is through a web app called <a href="http://www.phpmyadmin.net/home_page/index.php">phpMyAdmin</a>.  There are many other tools out there that you can use, but why use a tool when you&#8217;ve already got a command line to work with?</p>
<p>I used to use phpMyAdmin all the time.  I eventually found out, through many frustratingly lost hours, that phpMyAdmin doesn&#8217;t handle sql dumps very well.  So, the next best bet was to do a dump through the command line.  Ever since then, I began playing around with the database with the command line, and now it is my preferred method of working with the database.</p>
<p>This post will eventually grow to hopefully be a good reference for myself, and hopefully for you as well.  I encourage all of you to learn this stuff.  It will be worth it.  As for now,  the list here will be short, but I hope to grow it.  If you have any specific requests, or better ways to do anything I&#8217;ve written here, please post a comment.</p>
<h3>Connecting to the Database</h3>
<p><code>mysql -u USERNAME -p -h 100.100.100.100 --port 3306 DATABASE;</code></p>
<p><strong>Explanation:</strong></p>
<ul>
<li>-u: Tells mysql that username you want to use</li>
<li>-p: Tells mysql to prompt you for your password</li>
<li>-h: Tells mysql what host to use (can be an IP address, or a domain.com)</li>
<li>&ndash;&ndash;port: Tells mysql what port to connect to</li>
<li>DATABASE: This you would replace with what database you want to connect to</li>
</ul>
<p>If you have connected to the server already via SSH, you do not need to supply the host.  You usually don&#8217;t need to supply the port, however, there will be cases that you need to supply one (ie: if you are running MAMP or WAMP, the database port is 8889).  If the database has no password, you do not need to supply the -p.</p>
<h3>Listing the Databases and Tables</h3>
<p><code>#Display the databases<br />
show databases;<br />
&nbsp;<br />
#Select a database to use<br />
use yourdatabase;<br />
&nbsp;<br />
#Display the tables of that database<br />
show tables;</code></p>
<h3>Play Around</h3>
<p>More to come.  If you get connected and select a database to use, play around with what you know.  This is all just standard MySQL commands.  Try starting out with &#8220;SELECT * FROM yourtable;&#8221; and see what happens.  If you haven&#8217;t used the command line before, you&#8217;ll be impressed with how the tables are displayed.  Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/09/16/using-mysql-through-the-command-line/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connecting to Multiple MySQL Databases with PHP</title>
		<link>http://devzone.pratthost.com/2008/09/15/connecting-to-multiple-mysql-databases-with-php/</link>
		<comments>http://devzone.pratthost.com/2008/09/15/connecting-to-multiple-mysql-databases-with-php/#comments</comments>
		<pubDate>Mon, 15 Sep 2008 21:11:54 +0000</pubDate>
		<dc:creator>Josh Pratt</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://devzone.pratthost.com/?p=39</guid>
		<description><![CDATA[I ran into a case where I needed to connect to two seperate databases within the same script, and I didn&#8217;t know how to do it without closing one connection, and opening another.  With a little time and effort, I figured it out, and it&#8217;s quite simple. Here is the PHP code to connect to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://devzone.pratthost.com/wp-content/uploads/2008/09/icon_database.jpg" rel="lightbox[39]"><img src="http://devzone.pratthost.com/wp-content/uploads/2008/09/icon_database.jpg" alt="" title="Database Icon" width="109" height="80" class="alignleft size-full wp-image-40" /></a></p>
<p>I ran into a case where I needed to connect to two seperate databases within the same script, and I didn&#8217;t know how to do it without closing one connection, and opening another.  With a little time and effort, I figured it out, and it&#8217;s quite simple.</p>
<p>Here is the PHP code to connect to a database:</p>
<p><code>$db1 = mysql_connect('localhost', 'db-user', 'db-password');<br />
mysql_select_db('db-name',$db1);</code></p>
<p>What this does is store the connection link in the variable $db1.  Then you choose which database to you with the second line.  With this code, you can then run mysql commands just like this:</p>
<p><code>$query = mysql_query("SELECT * FROM yourtable;);</code></p>
<p>Now, in the case where you need to do some work with a different database, you don&#8217;t want to be closing and opening connections all the time.  So, when you make your database connections, it&#8217;s very easy.  This is what the code looks like with 3 database connections open (of course, you&#8217;d have to change all the variables for each different database):</p>
<p><code>$db1 = mysql_connect('localhost', 'db-user', 'db-password');<br />
mysql_select_db('db-name', $db1);<br />
$db2 = mysql_connect('localhost', 'db-user', 'db-password');<br />
mysql_select_db('db-name', $db2);<br />
$db3 = mysql_connect('localhost', 'db-user', 'db-password');<br />
mysql_select_db('db-name', $db3);</code></p>
<p>You will probably want to rename the $db1 varables with something more suggestive of which database you are using just for clarity.  Now, to use these different database connections, all you have to do is add that connection link to the end of your query like this:</p>
<p><code>$query1 = mysql_query("SELECT * FROM yourtable", $db1);<br />
$query2 = mysql_query("SELECT * FROM differenttable ORDER BY column DESC", $db2);<br />
$query3 = mysql_query("SELECT somevalue FROM table WHERE id = 20", $db3);</code></p>
<p>And that&#8217;s all there is to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://devzone.pratthost.com/2008/09/15/connecting-to-multiple-mysql-databases-with-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
