<?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>Albert Fama &#187; MySQL</title>
	<atom:link href="http://albertfama.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://albertfama.com</link>
	<description>Freelance Web Programmer - specializing in PHP &#38; MySQL</description>
	<lastBuildDate>Fri, 20 Nov 2009 16:06:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MySQL returns strings&#8230;or does it?</title>
		<link>http://albertfama.com/php/mysql-returns-stringsor-does-it/</link>
		<comments>http://albertfama.com/php/mysql-returns-stringsor-does-it/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 14:04:25 +0000</pubDate>
		<dc:creator>Albert Fama</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Variables]]></category>
		<category><![CDATA[Types]]></category>
		<category><![CDATA[variable types]]></category>

		<guid isPermaLink="false">http://obnexus.net/?p=23</guid>
		<description><![CDATA[I noticed an interesting fact yesterday, which pertains to my original post MySQL returns strings (if you have not read this yet, please do).  The PHP function mysql_num_rows(), which returns the number of rows in a result set, I assumed would return the number of rows as a string.  Since field values are [...]]]></description>
			<content:encoded><![CDATA[<p>I noticed an interesting fact yesterday, which pertains to my original post <a href="/php/mysql-returns-strings/" title="albertfama.com: MySQL returns strings">MySQL returns strings</a> (if you have not read this yet, please do).  The PHP function <a title="PHP Manual: mysql_num_rows" href="http://us3.php.net/mysql_num_rows" title="MySQL returns strings" >mysql_num_rows()</a>, which returns the number of rows in a result set, I assumed would return the number of rows as a string.  Since field values are all returned as strings and for the sake of consistency my initial thought was that this function would also return a string.</p>
<p>One of the first things you should learn as a developer (or human) is to never assume, so I checked the documentation, and to my surprise I was completely wrong, the number actually arrives in PHP as an INT type.</p>
<p>The MySQL C API function <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-num-rows.html" title="MySQL Manual: mysql_num_rows" >mysql_num_rows()</a> returns a <a href="http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html#id2713549" title="MySQL Manual: my_ulonglong" >my_ulonglong</a> value:</p>
<blockquote><p><a rel="nofollow" href="http://www.amazon.com/MySQL-Developers-Library-Paul-DuBois/dp/0672326736/ref=pd_bbs_sr_2/103-4441044-9682228?ie=UTF8&amp;s=books&amp;qid=1192635085&amp;sr=1-2" title="Amazon: MySQL - Paul DuBois" >MySQL &#8211; Paul DuBois</a><br />
my_ulonglong &#8211; A long integer type, used for the return value of functions that return row counts or other potentially large numbers, such as mysql_affected_rows(), mysql_num_rows(), and mysql_insert_id()&#8230;</p></blockquote>
<p>This information again had me looking through the documentation in the PHP manual and in fact <a href="http://us3.php.net/manual/en/function.mysql-insert-id.php" title="PHP Manual: mysql_insert_id()" >mysql_insert_id()</a> does return an INT type (or FALSE on failure).</p>
<p>I find it interesting that in certain situations the data type coming from the MySQL C API is actually representative of the content of the data and at other times it is not. Not that this gets us any closer to why field values are all returned as strings, but the plot does thicken.</p>
<p>If anyone can shed any light on this topic, or would like to put their own spin on things, please feel free to comment.</p>
<p>In the next couple of days I will write a post explaining how, as a PHP developer, I became interested in variable types, and why you should also.</p>

                            <div id="aspdf">
                                <a href="http://albertfama.com/wp-content/plugins/as-pdf/generate.php?post=23">
                                    <span>&nbsp;</span>
                                </a>
                            </div>
                        ]]></content:encoded>
			<wfw:commentRss>http://albertfama.com/php/mysql-returns-stringsor-does-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL returns strings</title>
		<link>http://albertfama.com/php/mysql-returns-strings/</link>
		<comments>http://albertfama.com/php/mysql-returns-strings/#comments</comments>
		<pubDate>Tue, 16 Oct 2007 22:44:48 +0000</pubDate>
		<dc:creator>Albert Fama</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Types]]></category>
		<category><![CDATA[variable types]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://obnexus.net/?p=22</guid>
		<description><![CDATA[This is a feature I have run into a few times (specifically when writing the unit tests for the Mysql Package). I thought I would post my thoughts and hopefully others will be able to expand on the topic.
When querying data out of MySQL into PHP, all values arrive in PHP as strings, even if [...]]]></description>
			<content:encoded><![CDATA[<p>This is a <em>feature</em> I have run into a few times (specifically when writing the unit tests for the <a href="/packages/mysql-package/" title="albertfama.com: Mysql Package">Mysql Package</a>). I thought I would post my thoughts and hopefully others will be able to expand on the topic.</p>
<p>When querying data out of MySQL into PHP, all values arrive in PHP as strings, even if the MySQL column type is INT. This <strong>is</strong> documented behavior:</p>
<blockquote><p>
PHP Manual &#8211; <a href="http://www.php.net/manual/en/function.mysql-fetch-array.php"  title="PHP Manual - mysql_fetch_array">mysql_fetch_array</a>&#8230;<br />
Returns an array of strings that corresponds to the fetched row&#8230;
</p></blockquote>
<p>I understand that PHP is a loosely typed language, which means PHP will convert the string to an integer on the fly (if it is deemed appropriate); but my question is: Why do integers arrive in PHP as strings?</p>
<p>A little research into the topic shows that the integer to string conversion actually happens outside the scope of PHP and lies in the MySQL C API. The <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html"  title="MySQL C API - mysql_fetch_row"> mysql_fetch_row()</a> function (within the C API) returns the data type <a href="http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html#id3008291"  title="MySQL C API - MYSQL_ROW">MYSQL_ROW</a>, which is defined as:</p>
<blockquote><p>
A type-safe representation of one row of data. It is currently implemented as an array of counted byte strings. (You cannot treat these as null-terminated strings if field values may contain binary data, because such values may contain null bytes internally.) Rows are obtained by calling mysql_fetch_row().</p></blockquote>
<p>I have asked in a few forums and chat rooms about this, but was never really able to get a definitive answer. Most people say that since PHP is loosely typed it doesn&#8217;t matter, which I cannot accept as an answer, especially since the MySQL C API is not used exclusively for loosely typed languages.</p>
<p>One theory I heard is that since the C API is used in many different languages for connecting to MySQL, the creators decided it would simply be easier to return all values as strings. This could possibly be the case, but I do not know of a common language which could not handle an integer.</p>
<p>Has anyone else looked into this topic before, or do you have the answer that has eluded me?</p>

                            <div id="aspdf">
                                <a href="http://albertfama.com/wp-content/plugins/as-pdf/generate.php?post=22">
                                    <span>&nbsp;</span>
                                </a>
                            </div>
                        ]]></content:encoded>
			<wfw:commentRss>http://albertfama.com/php/mysql-returns-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql Package Released</title>
		<link>http://albertfama.com/php/mysql-package-released/</link>
		<comments>http://albertfama.com/php/mysql-package-released/#comments</comments>
		<pubDate>Wed, 25 Jul 2007 14:13:36 +0000</pubDate>
		<dc:creator>Albert Fama</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Packages]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[download]]></category>

		<guid isPermaLink="false">http://obnexus.net/?p=15</guid>
		<description><![CDATA[I just wanted to officially announce that my first package is available for download.
I decided to release the Mysql Package first. This was done for three reasons. 

Usefulness &#8211; After using PHP for a few days everyone inevitably wants to add a database to there repertoire.  Since the most common database coupled with PHP [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to officially announce that my first package is available for download.</p>
<p>I decided to release the <a href="/packages/mysql-package/" title="albertfama.com: MySQL Package">Mysql Package</a> first. This was done for three reasons. </p>
<ul>
<li style="margin-bottom: 10px;"><strong>Usefulness</strong> &#8211; After using PHP for a few days everyone inevitably wants to add a database to there repertoire.  Since the most common database coupled with PHP (by my calculation) is <a href="http://mysql.com"  title="MySQL Website">MySQL</a> why not create a MySQL package.
</li>
<li style="margin-bottom: 10px;"><strong>Basic</strong> &#8211; The package I created is very basic giving novices a chance to get up and running quickly, and to see what <a href="http://www.webreference.com/programming/phpanth2/" >OOP</a> is all about.</li>
<li style="margin-bottom: 10px;"><strong>Example of my work</strong> &#8211; I understand that if you are no longer a PHP novice you will already have a database package which you use and prefer, but by releasing this package first, you will be able to review the code quickly and determine the quality of code I produce. Hopefully this will keep you interested in my growing library.</li>
</ul>
<p>A little about the <a href="/packages/mysql-package/" title="albertfama.com: MySQL Package">Mysql Package</a>:<br />
The package is designed to provide basic functionality for connecting, querying, data retrieval, and error reporting against a MySQL database server.</p>
<p>The package is divided into 4 main classes (with a fifth typed exception).</p>
<p>Hope you all enjoy, and keep those comments coming.</p>
<p>Thank you.</p>

                            <div id="aspdf">
                                <a href="http://albertfama.com/wp-content/plugins/as-pdf/generate.php?post=15">
                                    <span>&nbsp;</span>
                                </a>
                            </div>
                        ]]></content:encoded>
			<wfw:commentRss>http://albertfama.com/php/mysql-package-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
