|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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"
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 04:00:01 2025 UTC |
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 -------------------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" }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" }