Bug #51203 [NEW]: PDO prepared statements, execute returns false on second call without parameter

From: Date: Thu, 04 Mar 2010 14:49:24 +0000
Subject: Bug #51203 [NEW]: PDO prepared statements, execute returns false on second call without parameter
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-148246@lists.php.net to get a copy of this message
From:             
Operating system: Debian
PHP version:      5.3.1
Package:          MySQL related
Bug Type:         Bug
Bug description:PDO prepared statements, execute returns false on second call without parameter

Description:
------------
$sth->execute() returns false on second run but fetchColumn still returns a
value.

Test script:
---------------
$db = new PDO('mysql:dbname=XXXX;unix_socket=/tmp/mysql.sock;','XXXX',
'XXXX');


$sth2 = $db->prepare("SELECT id FROM users ORDER BY RAND()");
$sth2->execute();
$ret=$sth2->fetchColumn();
echo $ret."\n";
$fail=$sth2->execute();
$ret=$sth2->fetchColumn();
var_dump($fail, $ret);


$sth = $db->prepare("SELECT 1 FROM users where active=?");
if ($sth->execute(array(1))) {
	$ret=$sth->fetch();
	echo "1\n";
} else die("poo pdo\n");

if ($sth->execute(array(1))) {
	$ret=$sth->fetch();
	echo "2\n";
} else die(var_export($db->errorInfo(), true));

$sth1 = $db->prepare("SELECT 1 FROM users where active=1");
if ($sth1->execute()) {
	$ret=$sth1->fetch();
	echo "1\n";
} else die("poo pdo\n");

if ($sth1->execute()) {
	$ret=$sth1->fetch();
	echo "2\n";
} else die(var_export($db->errorInfo(), true));


die;



Expected result:
----------------
1033
bool(true)
string(4) "1142"
1
2
1
2

Actual result:
--------------
1033
bool(false)
string(4) "1142"
1
2
1
array (
  0 => '00000',
  1 => NULL,
  2 => NULL,
)


Relevant strace :

lose(4)                                = 0
socket(PF_FILE, SOCK_STREAM, 0)         = 4
fcntl64(4, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(4, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
connect(4, {sa_family=AF_FILE, path="/tmp/mysql.sock"...}, 17) = 0
fcntl64(4, F_SETFL, O_RDWR)             = 0
poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=4,
revents=POLLIN}])
recv(4, "8\0\0\0\n5.1.42-log\0\336\1\0\0JSE@MERN\0\377\367\10\2"..., 8192,
MSG_DONTWAIT) = 60
send(4,
"G\0\0\1\215\242\7\0\0\0\0\300\10\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...,
75, MSG_DONTWAIT) = 75
poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=4,
revents=POLLIN}])
recv(4, "\7\0\0\2\0\0\0\2\0\0\0"..., 8192, MSG_DONTWAIT) = 11
send(4, "%\0\0\0\3SELECT id FROM users ORDER B"..., 41, MSG_DONTWAIT) = 41
poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=4,
revents=POLLIN}])
recv(4, "\1\0\0\1\1,\0\0\2\3def\10mynatnet\5users\5user"..., 8192,
MSG_DONTWAIT) = 8192
poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=4,
revents=POLLIN}])
recv(4,
"1606\5\0\0\221\0041487\5\0\0\222\0041560\5\0\0\223\0041310\5\0"..., 8192,
MSG_DONTWAIT) = 7275
write(1, "1318\n"..., 5)                = 5
send(4, "%\0\0\0\3SELECT id FROM users ORDER B"..., 41, MSG_DONTWAIT) = 41
poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=4,
revents=POLLIN}])
recv(4, "\1\0\0\1\1,\0\0\2\3def\10mynatnet\5users\5user"..., 8192,
MSG_DONTWAIT) = 8192
poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=4,
revents=POLLIN}])
recv(4,
"\0\0\220\0042199\5\0\0\221\0041211\5\0\0\222\0041024\5\0\0\223\00423"...,
8192, MSG_DONTWAIT) = 7275
write(1, "bool(false)\n"..., 12)        = 12
write(1, "string(4) \""..., 11)         = 11
write(1, "1607"..., 4)                  = 4
write(1, "\"\n"..., 2)                  = 2


-- 
Edit bug report at http://bugs.php.net/bug.php?id=51203&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=51203&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=51203&r=trysnapshot53
Try a snapshot (PHP 6.0):            http://bugs.php.net/fix.php?id=51203&r=trysnapshot60
Fixed in SVN:                        http://bugs.php.net/fix.php?id=51203&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51203&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=51203&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=51203&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=51203&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=51203&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=51203&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=51203&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=51203&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=51203&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=51203&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=51203&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=51203&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=51203&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=51203&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=51203&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=51203&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=51203&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#148246) next »