php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51203 PDO prepared statements, execute returns false on second call without parameter
Submitted: 2010-03-04 15:49 UTC Modified: 2010-03-06 06:14 UTC
From: rolf at winmutt dot com Assigned:
Status: Duplicate Package: MySQL related
PHP Version: 5.3.1 OS: Debian
Private report: No CVE-ID: None
 [2010-03-04 15:49 UTC] rolf at winmutt dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-06 06:14 UTC] pierrick@php.net
-Status: Open +Status: Duplicate
 [2010-03-06 06:14 UTC] pierrick@php.net
This is the same bug as #45120 which was fixed in 5.3.2.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Oct 25 18:03:49 2021 UTC