E.g.
http://it.php.net/manual/en/pdo.query.php
orIf you do not fetch all of the data in a result set before issuing your next call to PDO::query(), your call may fail. Call PDOStatement::closeCursor() to release the database resources associated with the PDOStatement object before issuing your next call to PDO::query().
http://it.php.net/manual/en/pdostatemen ... .php#84495
That means that one has to make more than one connection to DB if multiple result sets are needed at the same time. Is that true?Be careful with fetch() when you use prepared statements and MySQL (I don`t know how it is with other databases). Fetch won`t close cursor and won`t let you send any other query, even if your result set has only one row, .
If you use $statement->fetch(), you will also have to use $statement->closeCursor() afterwards, to be albe to execute another query.
Alternatively you can use $statement->fetchAll() without $statement->closeCursor().
Let's see:
I test that with mySql 5.0.51a and php PHP Version 5.2.5 under Windows XP with xampp 1.6.2
Code: Select all
$stm1=$dbh->query("SELECT * FROM libri WHERE autore='rik'");
$row1=$stm1->fetch();
print_r($row1);
$stm2=$dbh->query("SELECT * FROM libri WHERE autore='bubu'");
$row2=$stm2->fetch();
print_r($row2);
$row1=$stm1->fetch();
print_r($row1);
$row2=$stm2->fetch();
print_r($row2);
The code above show correctly alternatively 1 item of a result set and of the other one without loosing anything, nor showing errors.
So, what's going on? Maybe that problem is only with some DB drivers? Are there special conditions to got the errors php manual is speaking about? Or the new PDO object corrected the problem and documentation still contains old notes (not updated)?.
It is important because that make the difference in approaching connection to DB: 1 for every resultsets or 1 for all?