php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56324 Can't seem to do more then one query per connection
Submitted: 2005-02-23 17:29 UTC Modified: 2005-02-27 18:33 UTC
From: lists at cyberlot dot net Assigned:
Status: Duplicate Package: PDO_MYSQL (PECL)
PHP Version: 5.0.3 OS: Fedore Core 3
Private report: No CVE-ID: None
 [2005-02-23 17:29 UTC] lists at cyberlot dot net
Description:
------------
Compiled from latest cvs I can't seem to do more then one query before pdo_mysql just dies. This is on a per object basis not on a overall basis as I can create a new object and perform another query

This seems to be limited to the use of the query function.. A single use of the query function seems to somehow taint the whole object preventing any further querys from happening.


Note the below function IF you move the query based statement from the last item to the first item the query will work but now the excute statements fail.

It doesn't matter what order I try soon as I run a $db1->query the object is useless for any futher querys.



Reproduce code:
---------------
                                                                                                                                                             
$dsn = 'mysql:dbname=mysql;host=localhost';
$db1 = new PDO($dsn, 'root', '');
                                                                                                                                                             
                                                                                                                                                             
$stm = $db1->prepare('SELECT * FROM help_category LIMIT 1');
$stm->execute();
print_r($stm->fetch(PDO_FETCH_ASSOC));
                                                                                                                                                             
$stm = $db1->prepare('SELECT * FROM help_category LIMIT 1');
$stm->execute();
print_r($stm->fetch(PDO_FETCH_ASSOC));
                                                                                                                                                             
$result = $db1->query('SELECT * FROM help_category LIMIT 1');
print_r($result->fetch(PDO_FETCH_ASSOC));


Expected result:
----------------
Array
(
    [help_category_id] => 0
    [name] => Point properties
    [parent_category_id] => 24
    [url] =>
)
Array
(
    [help_category_id] => 0
    [name] => Point properties
    [parent_category_id] => 24
    [url] =>
)
Array
(
    [help_category_id] => 0
    [name] => Point properties
    [parent_category_id] => 24
    [url] =>
)

Actual result:
--------------
Array
(
    [help_category_id] => 0
    [name] => Point properties
    [parent_category_id] => 24
    [url] =>
)
Array
(
    [help_category_id] => 0
    [name] => Point properties
    [parent_category_id] => 24
    [url] =>
)
 
Fatal error: Call to a member function fetch() on a non-object in /root/test.php on line 15


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-26 10:48 UTC] wez@php.net
please enable exception error mode by doing this after you create the object :

$db1->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);

and re-run the script, to determine why the mysql driver doesn't like about what you are doing.
 [2005-02-27 01:57 UTC] lists at cyberlot dot net
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2014 Commands out of sync;  You can't run this command now' in /root/test.php:18
Stack trace:
#0 /root/test.php(18): PDO->query('SELECT * FROM h...')
#1 {main}
  thrown in /root/test.php on line 18
[root@fs root]#
 [2005-02-27 16:03 UTC] wez@php.net
Duplicate of #3503.
This is actually intended behaviour; to fix your script, you should $stm = null; once you have finished used $stm.
 [2005-02-27 18:33 UTC] lists at cyberlot dot net
This only affects the query command, not the execute command, I have also never seen such behaviour in any other php functions before so it should be carefully documented.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC