<?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>Peter Törnstrand &#187; pdo</title>
	<atom:link href="http://www.tornstrand.com/tag/pdo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tornstrand.com</link>
	<description>Drupal, PHP and web developing</description>
	<lastBuildDate>Fri, 16 Apr 2010 07:04:56 +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>Garbeled data using PDO and MySQL</title>
		<link>http://www.tornstrand.com/2008/01/20/garbeled-data-using-pdo-and-mysql/</link>
		<comments>http://www.tornstrand.com/2008/01/20/garbeled-data-using-pdo-and-mysql/#comments</comments>
		<pubDate>Sun, 20 Jan 2008 15:00:43 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pdo]]></category>

		<guid isPermaLink="false">http://www.tornstrand.com/index.php/2008/01/20/garbeled-data-using-pdo-and-mysql/</guid>
		<description><![CDATA[Ran into some trouble the other day while emigrating a PHP solution from our development server to the production server. The application was working fine on the development server but once moved to the production server it started to behave strangely. Data returned from the datebase via stored procedures was contaning lots of garbeled data [...]]]></description>
			<content:encoded><![CDATA[<p>Ran into some trouble the other day while emigrating a PHP solution from our development server to the production server. The application was working fine on the development server but once moved to the production server it started to behave strangely.<span id="more-4"></span></p>
<p>Data returned from the datebase via stored procedures was contaning lots of garbeled data and results from previous select statments. So i turned to Google to find the answer to this strange behavior. Turns out this problem appears when executing a stored procedure contaning a <a href="http://dev.mysql.com/doc/refman/5.0/en/sqlps.html">PREPARE</a> statement. Why would one do this you might ask, well it has to do with MySQL inability to handle variables in the LIMIT clause. The only way to do paging with a stored procedure in MySQL is to use a PREPARE statement inside the procedure.</p>
<pre>DELIMITER $$
CREATE PROCEDURE paging (IN pageSize INT, IN position INT)
BEGIN
	PREPARE stmt FROM CONCAT("SELECT * FROM table LIMIT ", position ,", ", pageSize);
	EXECUTE stmt;
END $$
DELIMITER ;</pre>
<p>Since this problem only occured on the production server the solution was pretty clear, simply update MySQL and PHP to the latest stable releases and you&#8217;re fine.</p>
<p>Related links: <a href="http://bugs.mysql.com/bug.php?id=19008">Bug report on php.net</a>, <a href="http://bugs.mysql.com/bug.php?id=19008">Bug report on Mysql.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tornstrand.com/2008/01/20/garbeled-data-using-pdo-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
