<?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>computeraxe &#187; mysql</title>
	<atom:link href="http://computeraxe.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://computeraxe.com</link>
	<description>wordpress tips and tricks</description>
	<lastBuildDate>Thu, 26 Aug 2010 15:30:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Commands for Cron Jobs</title>
		<link>http://computeraxe.com/commands-for-cron-jobs/</link>
		<comments>http://computeraxe.com/commands-for-cron-jobs/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 18:46:30 +0000</pubDate>
		<dc:creator>axe</dc:creator>
				<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://computeraxe.com/?p=476</guid>
		<description><![CDATA[I got totally lost the other day when I couldn&#8217;t get a cron job to work. Now, what path was that? WordPress Database Backup is a plugin that I&#8217;d relied on in the past to keep a randomly backed up &#8230; <a href="http://computeraxe.com/commands-for-cron-jobs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I got totally lost the other day when I couldn&#8217;t get a cron job to work. Now, what path was that?</p>
<p>WordPress Database Backup is a plugin that I&#8217;d relied on in the past to keep a randomly backed up copy of a WordPress site. Unfortunately, that&#8217;s not a complete solution as the images or uploads folder, as well as any modified theme pages, won&#8217;t be saved during the database backup. Nor will the blog links! Keep an archive copy of everything you put on your website, so everything can be reconstructed in the case of a disaster or even a host switch. In case a website is made up of more than one database, you&#8217;d need a different backup solution than what a WordPress plugin can provide.</p>
<p>Use CRON jobs to automate the task of backing up all your hard work. It might take a while to figure things out, but once you do you&#8217;ll be secure in the knowledge that you did it and your data is safe.</p>
<p>At first I didn&#8217;t have the command part right for the cron job to work. After the time elements you need to indicate the path to sh, any flags (none used here), and the path to the shell script. In this case the command was -</p>
<p>/bin/sh /home/owner/backup/automysqlbackup.sh</p>
<p>where &#8220;owner&#8221; is the CPanel login name, and &#8220;backup&#8221; is an empty directory or folder that you create above the public_html directory. Some hosts will have a folder called &#8220;etc&#8221; already created for you. Check with your host!</p>
<p>In this case the /bin/sh directory was already created at the server level, in other words, I didn&#8217;t have to create it. The corresponding first line in the .sh file was -</p>
<p>#!/bin/sh</p>
<p>Originally, the .sh file had an opening #!/bin/bash, but that didn&#8217;t work on this particular host.</p>
<ul>
<li>A great <a title="cron commands" href="http://www.interspire.com/support/kb/questions/383/How+does+the+CRON+command+work%3F">explanation of CRON commands</a> is found in the rainbow. Nice touch, guys!</li>
<li>Best <a title="Set up automysqlbackup" href="http://freenuts.com/6-steps-to-back-up-your-blog-database-with-automysqlbackup/">explanation of setting up automysqlbackup</a> shell script.</li>
<li>Get the open source database backup script from sourceforge, <a title="automysqlbackup" href="http://sourceforge.net/projects/automysqlbackup/">automysqlbackup</a>.</li>
</ul>
<p>The host tells me the script is running successfully, so I know the lack of output is my fault &#8211; somewhere. Checks the paths&#8230;found it! An error in the path for the configuration file lead to the script trying to run with default parameters, some of them blank. The script ran as far as it could so there was no error reported by the cron daemon to my email address. When the output is successful a log file is sent to that address.</p>
<p>When I finally got the paths straightened out, the backup files were zipped and in their proper places and an email log was sent to the proper address at the time the cron job was to run. It worked! Now I&#8217;ll go back and set up a couple of other cron jobs to back up other databases. I&#8217;ll use the same script, modified to back up different sets of databases on different schedules.</p>
<ul>
<li>If you&#8217;re looking for a simple script to make one database backup and save that on your server, check out DaniWeb&#8217;s <a title="CRON job for backup" href="http://www.daniweb.com/forums/thread646.html">CRON job for backup</a>.</li>
<li><a title="backup home directory" href="http://www.alphaone-tech.com/tech-support/index.php?_m=knowledgebase&amp;_a=viewarticle&amp;kbarticleid=68">Backing up your home directory</a> is just as easy!</li>
</ul>
<p>Once you have your sites backed up automatically, you can do away with any backup plugins that you may have relied on in the past. When at all possible, automate the task of backing up a database. It&#8217;ll make your life easier!</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/commands-for-cron-jobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Format of Numerical Values Matters to Your MySQL Database</title>
		<link>http://computeraxe.com/format-numerical-values-mysql-database/</link>
		<comments>http://computeraxe.com/format-numerical-values-mysql-database/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 14:55:35 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://computeraxe.com/?p=253</guid>
		<description><![CDATA[In using databases we tend to move around a lot of data. So much data, in fact, that it&#8217;s impossible to verify every single datum in a manual way. What we can and should do is verify that the beginning, &#8230; <a href="http://computeraxe.com/format-numerical-values-mysql-database/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In using databases we tend to move around a lot of data. So much data, in fact, that it&#8217;s impossible to verify every single datum in a manual way. What we can and should do is verify that the beginning, middle and ends of the data are intact.</p>
<p>I ran into a solution for a problem that I didn&#8217;t know I had until I checked to see that data I had imported into an existing MySQL table was imported properly. Data at the beginning of the <a href="http://computeraxe.com/how-to-import-data-file-mysql-phpmyadmin/">new table mirrored the CSV nicely</a>, but near the middle of the table I found that certain columns of data were whole numbers, not the decimal figure I was supposed to find.</p>
<p>It&#8217;s important to check the <strong>format of numerical values</strong>. By using the wrong data type when setting up your database you stand to lose precision of your numbers.</p>
<p>For example, when I set up a database I erroneously used the INT data type for a couple of values that needed to show the decimal places. Integers are whole numbers, and therefore, a value like 5.78 in the CSV showed up as 6 in the database table. The software did exactly what I asked it to do, which is a good reason to always verify the data after any manipulations.</p>
<p>The fix was to change the structure of the fields by changing the data &#8216;Type&#8217; from INT to DECIMAL and specifying the &#8216;Length/Values&#8217; in the format of &#8216;N,n&#8217; where N is the total number of digits and n is the number of decimal places. So, for my example of 5.78, I entered &#8220;DECIMAL&#8221; and &#8220;3,2&#8243;.</p>
<p><img src="http://computeraxe.com/images/decimal-int.jpg" alt="Example of DECIMAL and INT numeric formats." /></p>
<p>Then, I imported the data again and ta-da! All the data was there in the proper format.</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/format-numerical-values-mysql-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Import a Data File into MySQL via phpMyAdmin</title>
		<link>http://computeraxe.com/how-to-import-data-file-mysql-phpmyadmin/</link>
		<comments>http://computeraxe.com/how-to-import-data-file-mysql-phpmyadmin/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 14:45:15 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://computeraxe.com/?p=247</guid>
		<description><![CDATA[Sometimes we have a need to read data into an existing database. Knowing how to import a data file into an established table can save you a lot of time. First, we&#8217;ll be working with MySQL and to make things &#8230; <a href="http://computeraxe.com/how-to-import-data-file-mysql-phpmyadmin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes we have a need to read data into an existing database. Knowing how to import a data file into an established table can save you a lot of time.</p>
<p>First, we&#8217;ll be working with MySQL and to make things easier we&#8217;ll use phpMyAdmin to speak to the database.</p>
<p>Second, obtain a delimited text file, which is basically a listing of table columns where each column of data is separated by, or marked off by, or <strong>delimited by </strong>a character. Common delimiting characters are the comma, semi-colon and quote marks, but any character may be used as long as you indicate what the delimiters are.</p>
<p><img src="http://computeraxe.com/images/csv-text.jpg" alt="Example character separated values or CSV file." /></p>
<p>In this example the tilde (~) encloses each field of text and the carat (^) denotes the end of the fields.</p>
<p>In phpMyAdmin select your database and table into which you want to import data and click on the Import tab.</p>
<p><img src="http://computeraxe.com/images/import-tab.jpg" alt="The Import tab of phpMyAdmin." /></p>
<p>Browse to the location of your delimited text file and select the character set of the file if the default is not correct.</p>
<p><img src="http://computeraxe.com/images/import-page.jpg" alt="The Import page in phpMyAdmin." /></p>
<p>Under &#8220;Format of imported file&#8221;, click CSV, which stands for comma separated values file or character separated values file. An options form will open when CSV is chosen, but if SQL is checked the options form remains hidden.</p>
<p><img src="http://computeraxe.com/images/import-csv.jpg" alt="Select the CSV button to open this part of the import page." /></p>
<p>Under &#8220;Options&#8221; you can tick off the boxes for &#8216;Replace table data with file&#8217; and &#8216;Ignore duplicate rows&#8217; if either function is desired.</p>
<p>Enter the characters that are appropriate for your CSV under &#8216;Fields terminated by&#8217; and &#8216;Fields enclosed by&#8217;. In the example file above &#8216;^&#8217; was used for the field termination character and &#8216;~&#8217; for the field enclosure character.</p>
<p>Characters for escaping fields or terminating lines can be input here, too. Also, if you want to add column names enter the names separated by commas in the blank provided. When ready, hit &#8220;Go&#8221;.</p>
<p>If successful, you&#8217;ll get a message that X number of queries were executed, which means that X number of records were imported into your table. If not successful, check the number of columns and the characters that you&#8217;ve input for the CSV and try again.</p>
<p>Your system may limit the size of file that can be imported. If so, check out this <a href="http://computeraxe.com/mysql-load-file-statement-rescues-huge-database-file/">LOAD FILE post</a> for a little help.</p>
<p>As always, verify that the data was read into the database correctly. Check that the data for each column of the table matches up with the source delimited text file.</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/how-to-import-data-file-mysql-phpmyadmin/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>MySQL LOAD FILE Statement Rescues Huge Database File</title>
		<link>http://computeraxe.com/mysql-load-file-statement-rescues-huge-database-file/</link>
		<comments>http://computeraxe.com/mysql-load-file-statement-rescues-huge-database-file/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 15:10:41 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://computeraxe.com/?p=241</guid>
		<description><![CDATA[A client needed to use an existing database, which turned out to be a big gargantuan thing, but to be able work with it on the Web I needed to convert it from MS Access to MySQL. Instead of trying &#8230; <a href="http://computeraxe.com/mysql-load-file-statement-rescues-huge-database-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A client needed to use an existing database, which turned out to be a big gargantuan thing, but to be able work with it on the Web I needed to convert it from MS Access to MySQL.</p>
<p>Instead of trying to convert the Access files to MySQL I chose to work with delimited text files that were available. Ten text files were used to represent ten tables for the database. It was easy enough to read in the delimited text files into OpenOffice Calc by identifying the delimiting characters and importing the new .csv file into MySQL, but one file in particular was <em>really</em> big and presented a problem.</p>
<p>I tried to work with the big text file in Notepad and HTML-Kit, but it was too cumbersome due to the file size &#8211; <em>over 500,000 records!</em> Not enough copy and paste operations could be done in a day to make me want to go through it again when the original database gets updated and I have to convert the scary big text file into MySQL format again. Knowing that the original database can be updated at any time, I needed a way to get that huge file into MySQL with a minimum of effort.</p>
<p>After looking around a bit, I downloaded a piece of conversion software called <a href="http://www.spectralcore.com/">Full Convert</a> from SpectralCore.</p>
<p>Installation went smoothly and I noted there was an uninstall feature in case the software wasn&#8217;t a good fit for my needs. It seemed promising in that there are several databases that can be converted back and forth, but the function to convert a text file to MySQL tables did not work for me. The text file used the characters &#8216;^&#8217; to terminate fields and &#8216;~&#8217; to enclose fields. However, the software did not give a choice for the field-enclosing character.</p>
<p>Since it didn&#8217;t work for me I uninstalled it, but the Full Convert software may be promising if you&#8217;re moving files from one database system to another. Here&#8217;s the list of DBs they work with:</p>
<blockquote><p><strong>Supported source databases</strong><br />
- Microsoft Access, dBase, FoxPro, Microsoft Excel documents, Interbase / Firebird, Lotus 1-2-3, MySQL, Oracle, PostgreSQL, ODBC sources, Paradox, SQL Server, Delimited text files, XML</p>
<p><strong>Supported target databases</strong><br />
- MySQL, SQL Server, Oracle, PostgreSQL, Access, Interbase/Firebird</p></blockquote>
<p>Further digging lead me to a solution for this problem of not being able to import a really big, delimited text file into a table in MySQL.</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/load-data.html">LOAD DATA INFILE</a></p>
<p>The solution is to read the file directly into MySQL using the MySQL statement &#8220;LOAD DATA INFILE&#8221;.</p>
<p>For my situation the code that worked was this -</p>
<p>LOAD DATA INFILE &#8216;data.txt&#8217; INTO TABLE databasename.tablename FIELDS TERMINATED BY &#8216;^&#8217; ENCLOSED BY &#8216;~&#8217;;</p>
<p>Don&#8217;t forget the trailing semi-colon and don&#8217;t use single quotes around the database and table names (and leave the semi-colon in the space provided for the Delimiter).</p>
<p>How did I find my solution? Searching at <a href="http://www.webmasterworld.com/forum88/13087.htm">WebmasterWorld</a> for &#8220;convert text to mysql&#8221; did the trick.</p>
<p>A simple post by a fellow developer that was written to help someone else out a couple years ago helped lead me to the LOAD_DATA function. Thanks, <a href="http://www.voyagerweb.co.uk/">dreamcatcher</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/mysql-load-file-statement-rescues-huge-database-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calendar Pick-A-Date Scripts Reviewed</title>
		<link>http://computeraxe.com/calendar-pick-a-date-scripts-reviewed/</link>
		<comments>http://computeraxe.com/calendar-pick-a-date-scripts-reviewed/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 15:51:41 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://computeraxe.com/?p=220</guid>
		<description><![CDATA[This week I needed to make a form where the user needed to enter two dates in order to produce a report with the selected start and end dates. What were my options? I considered writing my own php script &#8230; <a href="http://computeraxe.com/calendar-pick-a-date-scripts-reviewed/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This week I needed to make a form where the user needed to enter two dates in order to produce a report with the selected start and end dates. What were my options?</p>
<p>I considered writing my own php script where I would have separate pull-down boxes for the day, month and year to assure that there was no mistake as to the actual dates. That would take a little extra format massaging to create the date in MySQL format, so I looked for scripts that others had already written. Who wouldn&#8217;t?</p>
<p>Formatting dates can drive a person crazy. Does &#8217;06-08-2000&#8242; mean June 8th or the 6th of August? Writing for the Web should be universal. The month-day format that we tend to use in the U.S. is confusing to everybody else who uses the day-month format, and vice-versa.</p>
<p>Writing by hand I like to use this format &#8217;12-Mar-2000&#8242; so there is no ambiguity, but that format needs to be converted to &#8216;YYYY-MM-DD&#8217; format when sending dates to MySQL.</p>
<p>So, what are my requirements for such a Date-Picker Script?</p>
<ul>
<li>easy, intuitive for the user</li>
<li>easy for me with output in MySQL format (YYYY-MM-DD)</li>
<li>unrestricted license would be nice</li>
</ul>
<p>I tried a few different date picker scripts and decided upon SpiffyCalendar because it&#8217;s the most advanced, yet easily modified to suit my purposes. Also, there is an established support system via a Yahoo! user group. That&#8217;s really nice, and unexpected.</p>
<p>Here&#8217;s the scripts I tried and the pros and cons for each&#8230;most weren&#8217;t as user-friendly as SpiffyCalendar.</p>
<p>&nbsp;</p>
<h3><a href="http://www.phpclasses.org/browse/package/3611/download/zip.html">PHP Calendar</a></h3>
<ul>PROS</p>
<li>I like the look of this calendar, but it&#8217;s difficult to determine how to modify the calendar other than for css of calendar appearance.</li>
<li>Date output is already in MySQL format: YYYY-MM-DD</li>
</ul>
<ul>CONS</p>
<li>Can&#8217;t select year from calendar unless you click back or forward to the actual month.</li>
<li>Ugly and excessively long query strings in links.</li>
</ul>
<h3><a href="http://www.javascriptkit.com/script/script2/timestamp.shtml">DatePick</a></h3>
<ul>PROS</p>
<li>I like the little calendar icon.</li>
</ul>
<ul>CONS</p>
<li>Can&#8217;t select year from calendar unless you click back or forward to the actual month.</li>
<li>Timestamp is included. Don&#8217;t need it.</li>
<li>Relies on javascript and pop-up window to select date.</li>
<li>Calendar doesn&#8217;t update well when moving from month to month. Part of the calendar doesn&#8217;t get loaded in so all days are not selectable. Have to manually widen window to see all days.</li>
<li>Can&#8217;t select year directly, have to click through months to get to next year.</li>
<li>No directions on how to modify output.</li>
</ul>
<h3><a href="http://www.javascriptkit.com/script/script2/tengcalendar.shtml">DateTimePick</a></h3>
<ul>PROS</p>
<li>I like the little calendar icon.</li>
<li>Can modify output via provided directions.</li>
</ul>
<ul>CONS</p>
<li>Can&#8217;t select year from calendar unless you click back or forward to the actual month.</li>
<li>Relies on javascript and pop-up window to select date.</li>
<li>Calendar doesn&#8217;t update well when moving from month to month. Part of the calendar doesn&#8217;t get loaded in so all days are not selectable. Have to manually widen window to see all days.</li>
<li>Can select year directly, but calendar doesn&#8217;t update well.</li>
</ul>
<h3><a href="http://simplythebest.net/scripts/DHTML_scripts/javascripts/javascript_48.html">SpiffyCalendar</a></h3>
<p><del datetime="2010-08-26T15:28:02+00:00">Sign up to the Yahoo! Group to download the script.</del> <em>Script used to be offered at the now defunct GeoCities. The above link is the first place I found it posted afterwards.</em></p>
<ul>PROS</p>
<li>Calendar pops into page, not a separate window.</li>
<li>Can modify output via provided directions.</li>
<li>Can get help at Yahoo! Groups.</li>
<li>Unrestricted license.</li>
<li>Can refresh page containing calendars as link is not modified after picking a date or two.</li>
<li>Highlights holidays, although will have to remove Dec 1st developer&#8217;s birthday. (OK, modified holiday array in script on lines 86-87.)</li>
</ul>
<ul>CONS</p>
<li>Format of date will have to be modified for MySQL. (OK, Added <code>"cal1.dateFormat="yyyy-MM-dd";</code> after instantiation in header for calendar named &#8216;cal1&#8242;.)</li>
<li>Relies on javascript.</li>
<li>Had to modify the images folder location in the .js file to an absolute address, although things worked fine on my local server with a relative address.</li>
</ul>
<p>I&#8217;m sure there are plenty of these date-picker scripts floating around the Web. Do you have a different one to share with us? Leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/calendar-pick-a-date-scripts-reviewed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limit of 127 Points to Wrong Numeric Type</title>
		<link>http://computeraxe.com/limit-127-wrong-numeric-type/</link>
		<comments>http://computeraxe.com/limit-127-wrong-numeric-type/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 13:37:39 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://computeraxe.com/?p=141</guid>
		<description><![CDATA[Sometimes the simple things evade us when we&#8217;re caught up in the details. Thank goodness for manuals. It turns outs that the numeric type that you select for your database variables matters greatly &#8211; DUH! I had an occurrence last &#8230; <a href="http://computeraxe.com/limit-127-wrong-numeric-type/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes the simple things evade us when we&#8217;re caught up in the details. Thank goodness for manuals.</p>
<p>It turns outs that the numeric type that you select for your database variables matters greatly &#8211; DUH!</p>
<p>I had an occurrence last week where a client entered values over 200 in a form, yet when the numbers were stored in the MySQL database were capped at 127. At first the error wasn&#8217;t spotted but when multiple entries were reported with the same 127, it became obvious that something was wrong.</p>
<p>My error was using <em><strong>tinyint</strong></em> instead of <em><strong>smallint</strong></em> as the numeric data type when setting up the MySQL table.</p>
<p>The <a href="http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html">MySQL Manual</a> clearly gives us limits for each data type, as found in the following table:</p>
<div id="attachment_142" class="wp-caption aligncenter" style="width: 461px"><a href="http://computeraxe.com/wp-content/uploads/2008/10/numeric-data-type1.jpg"><img src="http://computeraxe.com/wp-content/uploads/2008/10/numeric-data-type1.jpg" alt="Numeric Data Types in MySQL" title="numeric-data-type" width="451" height="346" class="size-full wp-image-142" /></a><p class="wp-caption-text">Numeric Data Types in MySQL</p></div>
<p>I don&#8217;t think we&#8217;ll have an occasion to use BIGINT, but the other data types will definitely be of use.</p>
<p>When all else fails, RTFM!</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/limit-127-wrong-numeric-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Left Joins Produce Data Reports Using All Rows of One Table</title>
		<link>http://computeraxe.com/left-joins-produce-data-reports-using-all-rows-of-one-table/</link>
		<comments>http://computeraxe.com/left-joins-produce-data-reports-using-all-rows-of-one-table/#comments</comments>
		<pubDate>Thu, 01 May 2008 23:11:43 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://computeraxe.com/left-joins-produce-data-reports-using-all-rows-of-one-table/</guid>
		<description><![CDATA[A client needed to have several reports created that indicate the various training sessions and certifications that each member has achieved. Producing the reports required collating data from several mysql tables and that made the queries a little complex. SELECT &#8230; <a href="http://computeraxe.com/left-joins-produce-data-reports-using-all-rows-of-one-table/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A client needed to have several reports created that indicate the various training sessions and certifications that each member has achieved. Producing the reports required collating data from several mysql tables and that made the queries a little complex.</p>
<p>SELECT statements were used for the most part which combined data from up to nine different mysql tables for the most inclusive report. A problem surfaced in that the reports did not show all the members. Some of the newer members did not yet have accomplishments that would show up in the output. Instead of seeing blank values for the newbies, the output did not list those new people at all. The reports were incomplete without listing all the members.</p>
<p><img src="/img/81_html_output.jpg" alt="Not all members are listed in the report." /></p>
<p>It would be helpful to see those blanks in the report as a reminder that some of the new people still need to satisfy certain requirements.</p>
<p>LEFT JOINS to the rescue!</p>
<p>LEFT JOINs are used to combine data from several database tables that may or may not have content pertaining to all members. Using the LEFT JOIN having the members table on the left will retain all members in the final report whether or not they have entries in the associated tables.</p>
<p>Instead of using the regular construct, SELECT data-col1, data-col2, data-col3 FROM table1, table2 WHERE condition1 = condition2, a LEFT JOIN was used like so:</p>
<p>SELECT data-col1, data-col2, data-col3 FROM table1 LEFT OUTER JOIN table2 ON condition1 = condition2</p>
<p>where the two table names are separated by &#8220;LEFT OUTER JOIN&#8221; and the WHERE clause is changed to the ON condition.</p>
<p>Emphasis is given to the table named on the left, table1, so that all its rows will be retained through the SELECTing of columns even though null values are encountered.</p>
<p>Original code that produced a report without blank lines:</p>
<p>$fems = mysql_query(&#8220;SELECT `last_name`, `first_name`, MAX(`certs_ID`) AS mcrt, `fema_date`, `pin` FROM `members`, `fema`, `fema_attend`, `certs`, `sar-certs` WHERE `pin` = `mem_pin` AND `fema_ID` = `fema_ids` AND `member_pin` = `pin` AND `cert_ID` = `certs_ID` GROUP BY `last_name`, `first_name` &#8220;)</p>
<p>Updated code using LEFT JOINS that produced a complete report that contained blank lines:</p>
<p>$fems = mysql_query(&#8220;SELECT `last_name`, `first_name`, MAX(`certs_ID`) AS mcrt, `fema_date`, `pin` FROM `members` LEFT OUTER JOIN  `fema_attend` ON `pin` = `mem_pin` LEFT OUTER JOIN `fema` ON `fema_ID` = `fema_ids` LEFT OUTER JOIN `sar-certs` ON `member_pin` = `pin` LEFT OUTER JOIN `certs` ON `cert_ID` = `certs_ID` GROUP BY `last_name`, `first_name` &#8220;)</p>
<p><img src="/img/80_html_output.jpg" alt="All members present in the report using LEFT JOINs." /></p>
<p>You&#8217;ll need a new LEFT JOIN for each table that you want to tack onto the SELECT statement in order to keep the blank values in the output.</p>
<p>Keep smiling and keep reading!</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/left-joins-produce-data-reports-using-all-rows-of-one-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Null Values Handled Nicely with the PHP Error Suppression Operator</title>
		<link>http://computeraxe.com/null-values-handled-nicely-with-the-php-error-suppression-operator/</link>
		<comments>http://computeraxe.com/null-values-handled-nicely-with-the-php-error-suppression-operator/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 23:02:14 +0000</pubDate>
		<dc:creator>LizzyFin</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://computeraxe.com/null-values-handled-nicely-with-the-php-error-suppression-operator/</guid>
		<description><![CDATA[Working on some database reports for a client&#8217;s membership roster and such, I came across a simple solution in handling some types of errors. Error messages filled a column in one report that should have output whether certain requirements were &#8230; <a href="http://computeraxe.com/null-values-handled-nicely-with-the-php-error-suppression-operator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Working on some database reports for a client&#8217;s membership roster and such, I came across a simple solution in handling some types of errors. Error messages filled a column in one report that should have output whether certain requirements were met by individual members of the organization.</p>
<p>Here&#8217;s the queries and partial output in question:</p>
<p>$fems = mysql_query(&#8220;SELECT `last_name`, `first_name`, MAX(`certs_ID`) AS mcrt, `fema_date`, `pin` FROM `members` LEFT OUTER JOIN  `fema_attend` ON `pin` = `mem_pin` LEFT OUTER JOIN `fema` ON `fema_ID` = `fema_ids` LEFT OUTER JOIN `sar-certs` ON `member_pin` = `pin` LEFT OUTER JOIN `certs` ON `cert_ID` = `certs_ID` GROUP BY `last_name`, `first_name` &#8220;) or die (&#8220;Query failed here 12&#8243;);<br />
while ($fem = mysql_fetch_array($fems)) {<br />
echo &#8220;&lt;td&gt;$fem[last_name]&lt;/td&gt;&#8221;.&#8221; &lt;td&gt;$fem[first_name]&lt;/td&gt; &#8220;;</p>
<p>$high_cert = mysql_query(&#8220;SELECT `cert` FROM `certs` WHERE `cert_ID` = $certif[mcert]&#8220;);<br />
while ($high_cer = mysql_fetch_array($high_cert)) {<br />
echo &#8220;$high_cer[cert]&#8220;;<br />
}&#8230;</p>
<p>And, here&#8217;s part of the ugly report that code section produced:</p>
<p><img src="../img/76_ugly_query.jpg" alt="Ugly report." /></p>
<p>What&#8217;s happening here to produce the error is that one of the queries produces some null values for the newest members of the organization who haven&#8217;t completed some requirements as of yet.</p>
<p>While fetching values from the $fems array an error is dumped on the screen that states:<br />
<code>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\org_member.php on line 766</code></p>
<p>How did I figure out what that error meant? Using the tool phpmyadmin! Once you open phpMyAdmin and have selected your database, click on the SQL tab.</p>
<p><img src="../img/77_phpmyadmin.jpg" alt="phpMyAdmin and its SQL tab." /></p>
<p>I copied and pasted the first SELECT statement in the SQL box that is labeled &#8220;Run SQL query/queries on database psar-data:&#8221;, where psar-data is the name of my database.<br />
<img src="../img/78_phpmyadmin_sql.jpg" alt="SQL query inside phpMyAdmin." />SQL query inside phpMyAdmin.</p>
<p>The page that is returned after pressing <em>Go</em> shows the SQL query and its output that contains NULL values.</p>
<p><img src="../img/79_sql_output.jpg" alt="phpMyAdmin and its SQL tab and query." /></p>
<p>Now, when the data set was subjected to the second query the null values produced the invalid result resource warning error. The second query was this:</p>
<p>$high_crts = mysql_query(&#8220;SELECT `cert` FROM `certs` WHERE `cert_ID` = $fem[mcrt]&#8220;);<br />
while ($high_crt = mysql_fetch_array($high_crts)) {<br />
echo &#8220;$high_crt[cert]&#8220;;<br />
}</p>
<p>Outputting values to the screen from this query would be so much nicer if the error would go away and just leave a blank. This example is a perfect use for the @ operator, or PHP error suppression operator. When placed in front of a PHP function the @ operator does not output error statements and mess up your data reports.</p>
<p>In the case where null values are encountered by the PHP function mysql_fetch_array the ugly warning error is produced. Placing the @ operator directly in front of mysql_fetch_array, like so @mysql_fetch_array, gives the output we&#8217;re seeking.</p>
<p><img src="../img/80_html_output.jpg" alt="Output using the @ operator." /></p>
<p>Yes, that output looks more professional without the error message and shows exactly what we want. In this case the blanks are meaningful and show exactly where a member needs to complete certain requirements.</p>
]]></content:encoded>
			<wfw:commentRss>http://computeraxe.com/null-values-handled-nicely-with-the-php-error-suppression-operator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
