<?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>UZED &#187; Stored Procedure</title>
	<atom:link href="http://uzed.com.br/tag/stored-procedure/feed/" rel="self" type="application/rss+xml" />
	<link>http://uzed.com.br</link>
	<description>Informação Livre!</description>
	<lastBuildDate>Wed, 14 Jul 2010 06:03:16 +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>PHP + PDO + MySQL + Stored Procedure + PREPARE = Problem</title>
		<link>http://uzed.com.br/php-pdo-mysql-stored-procedure-prepare-problem/</link>
		<comments>http://uzed.com.br/php-pdo-mysql-stored-procedure-prepare-problem/#comments</comments>
		<pubDate>Fri, 31 Aug 2007 16:50:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PDO]]></category>
		<category><![CDATA[Stored Procedure]]></category>

		<guid isPermaLink="false">http://uzed.com.br/zed/?p=21</guid>
		<description><![CDATA[Eu descobri um erro quando estava fazendo o meu script em PHP usando o conector PDO. (I&#8217;ve found a bug when working on a PHP script using a PDO connector.) Quando fiz uma Stored Procedure usando o recurso PREPARE dentro, ocorreu um problema com o resultado do meu script em PHP. (When I made a [...]]]></description>
			<content:encoded><![CDATA[<p>Eu descobri um erro quando estava fazendo o meu script em PHP usando o conector PDO.<br />
(<em>I&#8217;ve found a bug when working on a PHP script using a PDO connector.</em>)</p>
<p>Quando fiz uma Stored Procedure usando o recurso PREPARE dentro, ocorreu um problema com o resultado do meu script em PHP.<br />
(<em>When I made a Store Procedure using the PREPARE statement something messed up the result im my PHP script.</em>)</p>
<h3>Config:</h3>
<p><strong>System:</strong> Linux Debian 2.6.21-2-486<br />
<strong>Apache:</strong> Apache 2.0 Handler<br />
<strong>PHP: </strong>Version 5.2.3-1+b1<br />
<strong>MySQL:</strong> 5.0.45</p>
<p>Seguem abaixo os códigos:<br />
(<em>The code is shown below:</em>)</p>
<p></p>
<h3>Estrutura da tabela (<em>Table Structure</em>)</h3>
<pre lang="SQL">
CREATE TABLE `tb_user` (
  `cd_user` int(11) NOT NULL auto_increment,
  `login` varchar(32) NOT NULL,
  `password` varchar(32) NOT NULL,
  PRIMARY KEY  (`cd_user`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- INSERT tb_user
-- 

INSERT INTO `tb_user` VALUES (1, 'lula', 'lele');
INSERT INTO `tb_user` VALUES (2, 'php', 'cool');
</pre>
<p></p>
<h3>Stored Procedure SELECT</h3>
<pre lang="SQL">
DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`sp_test_select`$$
CREATE PROCEDURE `test`.`sp_test_select` ()
BEGIN

	SELECT login,password FROM test.tb_user;

END$$

DELIMITER ;
</pre>
<p></p>
<h3>Stored Procedure PREPARE</h3>
<pre lang="SQL">
DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`sp_test_prepare`$$
CREATE PROCEDURE `test`.`sp_test_prepare` ()
BEGIN

	PREPARE s1 FROM 'SELECT login,password FROM test.tb_user';
	EXECUTE s1;
	DEALLOCATE PREPARE s1;

END$$

DELIMITER ;
</pre>
<p></p>
<h3>Código PHP (<em>PHP Code</em>)</h3>
<pre lang="PHP">
function result($sql)
{
    $db = new PDO('mysql:dbname=test;host=127.0.0.1', 'test','test');
    $stm = $db->prepare($sql);
    $stm->execute();

    echo "\n######## $sql #######\n";

    while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
        echo $row["login"]." - ".$row["password"]."\n";
    }   

    $db = null;
    $stm = null;
}   

result("SELECT * FROM tb_user");

result("CALL sp_test_select()");

result("CALL sp_test_prepare()");
</pre>
<p></p>
<h3>Resultado (<em>Result</em>)</h3>
<pre lang="SH">
zed:/www/directdial/tmp# php pdo.php 

######## SELECT * FROM tb_user #######
lula - lele
php - cool

######## CALL sp_test_select() #######
lula - lele
php - cool

######## CALL sp_test_prepare() #######
 -
pcoolb_usertb_usepassworpassword
                                 Ã½Â¨ÂˆÂ”Â?Â½test -
</pre>
<p>
Aqui esta o problema, quando chamo CALL sp_test_prepare() pelo PDO , ele não retorna corretamente os valores.<br />
(<em>Here lies the problem. When I call CALL sp_test_prepare() through PDO, it does not return the values as it should.</em>)
</p>
<p>
Se você sabe como resolver este problema, por favor poste um comentário.<br />
(<em>If you know how to fix this bug, please comment on this thread.</em>)
</p>
<p></p>
<h3>Resolução</h3>
<p>Encontrei a resposta no seguinte link:<br />
<a href="http://pecl.php.net/bugs/bug.php?id=7365">http://pecl.php.net/bugs/bug.php?id=7365</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uzed.com.br/php-pdo-mysql-stored-procedure-prepare-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
