php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47504 error "SQLSTATE[HY000]: General error: 2014" with sql comments
Submitted: 2009-02-25 21:07 UTC Modified: 2009-02-28 09:10 UTC
From: admin at ifyouwantblood dot de Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.8 OS: Windows XP SP 3
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
14 + 39 = ?
Subscribe to this entry?

 
 [2009-02-25 21:07 UTC] admin at ifyouwantblood dot de
Description:
------------
i get this error with following code:

-------------
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. HY000

#0 D:\_projects\web\1.php(13): PDO->query('INSERT INTO `te...')
#1 {main} 
--------------

removing !SQL COMMENTS! will solve this. this only appears on windows (XP), linux is fine. mysql version is 5.0.51a. latest XAMPP package was used to test this (without modifications).

Reproduce code:
---------------
<?php

set_exception_handler('ehandler');

$pdo=new PDO('mysql:dbname=barcodescanner;host=127.0.0.1','root','');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo->query(' CREATE TABLE IF NOT EXISTS `test` (
`some` VARCHAR( 100 ) NOT NULL
) ENGINE = INNODB ');
$pdo->query('SET TRANSACTION ISOLATION LEVEL SERIALIZABLE');
$pdo->query('START TRANSACTION');
$pdo->query("INSERT INTO `test` (some) VALUES ('1111111111111111'), ('1111111111111'); -- I AM AN SQL COMMENT, REMOVING ME WILL SOLVE THIS PROBLEM");
$pdo->query("INSERT INTO `test` (some) VALUES ('1111111111111111'), ('1111111111111')");
$pdo->query('COMMIT');



function ehandler($exception)
{
        echo '<pre>'."\r\n";
        echo $exception->getMessage().' '.$exception->getCode();
        echo "\r\n\r\n";
        echo $exception->getTraceAsString();
        echo '</pre>';
} 

Expected result:
----------------
nothing

Actual result:
--------------
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. HY000

#0 D:\_projects\web\1.php(13): PDO->query('INSERT INTO `te...')
#1 {main} 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-28 07:40 UTC] admin at ifyouwantblood dot de
also appears in 5.2.9
 [2009-02-28 09:10 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$pdo->query("INSERT INTO `test` (some) VALUES ('1111111111111111'),
('1111111111111'); -- I AM AN SQL COMMENT, REMOVING ME WILL SOLVE THIS
PROBLEM");

Due to the ";" this is a multi-statement, executing two queries while the second is only a comment. The second "result" can be accessed using PDOStatement->nextRowset.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC