|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-10-24 03:52 UTC] akorthaus at web dot de
Description:
------------
If I want to use PDO::query() more than one time in a script, I have to set the last PDOStatement to NULL, before I can use the second query. Only If I add:
$stmt1 = NULL;
before
$stmt2 = $db->query ...
in the example below, I can work with the second query.
But - how can I work with two statments at the same time? I often have to do this! I don't understand it because I use two different variables for the statements here.
I have used the pdo_mysql driver (MySQL 4.1.14), pdo and pdo_mysql were compiled from latest CVS.
Reproduce code:
---------------
<?php
$db = new PDO('...');
$stmt1 = $db->query('SELECT * FROM table1');
var_dump($stmt1);
$stmt2 = $db->query('SELECT * FROM table2');
var_dump($stmt1);
?>
Expected result:
----------------
object(PDOStatement)#2 ...
object(PDOStatement)#2 ...
Actual result:
--------------
object(PDOStatement)#2 ...
bool(false)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 03:00:01 2025 UTC |
that's how this problem could also look like: <?php $db = new PDO('...'); $stmt = $db->query('SELECT * FROM table1'); var_dump($stmt); $stmt = $db->query('SELECT * FROM table2'); var_dump($stmt); $stmt = $db->query('SELECT * FROM table3'); var_dump($stmt); ?> output: ------------------------- object(PDOStatement)#2 ... bool(false) object(PDOStatement)#2 ... Only if I do this: <?php $db = new PDO('...'); $stmt = $db->query('SELECT * FROM table1'); var_dump($stmt); $stmt = NULL; $stmt = $db->query('SELECT * FROM table2'); var_dump($stmt); $stmt = NULL; $stmt = $db->query('SELECT * FROM table3'); var_dump($stmt); $stmt = NULL; ?> output: ------------------------- object(PDOStatement)#2 ... object(PDOStatement)#2 ... object(PDOStatement)#2 ... This seems to work. But should this really be the way to go? I hope it's a but ;-)