php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36788 prepared statements broken
Submitted: 2006-03-19 16:00 UTC Modified: 2006-03-28 01:00 UTC
From: bubblenut at gmail dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.1.2 OS: Linux 2.6.12 (Kubuntu)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bubblenut at gmail dot com
New email:
PHP Version: OS:

 

 [2006-03-19 16:00 UTC] bubblenut at gmail dot com
Description:
------------
It works fine on my Debian Sarge machine but on my Kubuntu laptop it fails. 
I have tried it with the follwing releases
PHP 5.1.0 CVS
PHP 5.1.1
PHP 5.1.2
PHP 5.1.2 CVS

Reproduce code:
---------------
<?php
//phpinfo();

$db   = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT id FROM recipe WHERE id=?");
$stmt->bindValue(1, 1);
$stmt->execute();
$res = $stmt->fetch();
var_dump($res);

$stmt = $db->prepare("SELECT id FROM recipe WHERE id=1");
$res  = $stmt->fetch();
var_dump($res);

foreach($db->query("SELECT id FROM recipe WHERE id=1") as $res) {
    var_dump($res);
}


Expected result:
----------------
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}


Actual result:
--------------
bool(false)
bool(false)
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-19 22:47 UTC] tony2001@php.net
This is what I get with your code (and this is expected):
-------------------
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.' in /tmp/1.php:11
Stack trace:
#0 /tmp/1.php(11): PDO->prepare('SELECT id FROM ...')
#1 {main}
  thrown in /tmp/1.php on line 11
-------------------
 [2006-03-20 00:29 UTC] bubblenut at gmail dot com
OK, so change the fetches for fetchAlls an alter the expected and actual results acordingly (yes I have tested with those methods). The bug still stands. Prepared statements are not working for this install.
 [2006-03-20 00:40 UTC] tony2001@php.net
It still doesn't work without execute() after prepare().
And after adding this execute() call, it works _just fine_.
 [2006-03-20 00:55 UTC] bubblenut at gmail dot com
Ahh, sorry, little typo, OK it looks like it's just in the parameter insertion then (do I need to start a new bug report?)

Revised Code
------------
<?php
//phpinfo();

$db   = new PDO('mysql:host=localhost;dbname=test', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $db->prepare("SELECT id FROM recipe WHERE id=?");
$stmt->bindValue(1, 1);
$stmt->execute();
$res = $stmt->fetchAll();
var_dump($res);

$stmt = $db->prepare("SELECT id FROM recipe WHERE id=1");
$stmt->execute();
$res  = $stmt->fetchAll();
var_dump($res);

foreach($db->query("SELECT id FROM recipe WHERE id=1") as $res) {
    var_dump($res);
}

Expected Result
---------------
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
  }
}
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
  }
}
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}

Actual Result
-------------
array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
  }
}
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
 [2006-03-20 11:09 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.1-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.1-win32-latest.zip


 [2006-03-20 11:35 UTC] bubblenut at gmail dot com
I get the following error when doing the make install

SECURITY ERROR: PHP_Archive::mapPhar can only be called from within the phar that initiates itInstalling PDO headers:          /usr/local/php/include/php/ext/pdo/


Also earlier in the make install I get the following libtool warning
libtool: install: warning: remember to run `libtool --finish /usr/local/src/php5.1-200603200930/libs'
 [2006-03-20 11:41 UTC] bubblenut at gmail dot com
Discovered that I can still use php but I'm still getting the same result

array(0) {
}
array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    string(1) "1"
    [0]=>
    string(1) "1"
  }
}
array(2) {
  ["id"]=>
  string(1) "1"
  [0]=>
  string(1) "1"
}
 [2006-03-20 11:42 UTC] tony2001@php.net
Ignore them. I believe you don't need PEAR to test PDO.
 [2006-03-28 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC