Bug #62528 [NEW]: PDO disregards SQL comments and throws parameter number exceptions

From: Date: Wed, 11 Jul 2012 07:54:23 +0000
Subject: Bug #62528 [NEW]: PDO disregards SQL comments and throws parameter number exceptions
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-171867@lists.php.net to get a copy of this message
From:             robin at industrialwebs dot nl
Operating system: Independent
PHP version:      Irrelevant
Package:          PDO related
Bug Type:         Bug
Bug description:PDO disregards SQL comments and throws parameter number exceptions

Description:
------------
Description can also be found here:
http://stackoverflow.com/questions/11415314/pdo-invalid-parameter-number-parameters-in-comments/

The problem is simple: PDO throws an exception when using named or
positional parameters in SQL comments. This is unexpected behaviour and
costed me quite a while to figure out.

The thrown exceptions for named and positional parameters are,
respectively:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]:
Invalid parameter number:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]:
Invalid parameter number: mixed named and positional parameters

Test script:
---------------
Try executing this query using PDO:

SELECT
    x
FROM
    y
WHERE
    -- CHECKING IF X = ? --
    x = :y
AND
    1 = 2

Or this one:

SELECT
    x
FROM
    y
WHERE
    -- CHECKING IF X = :Z --
    x = :y
AND
    1 = 2

Expected result:
----------------
This should execute the query with only :Z as bound parameter.

Actual result:
--------------
Exceptions because parameters in comments get parsed.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62528&edit=1
-- 
Try a snapshot (PHP 5.4):            https://bugs.php.net/fix.php?id=62528&r=trysnapshot54
Try a snapshot (PHP 5.3):            https://bugs.php.net/fix.php?id=62528&r=trysnapshot53
Try a snapshot (trunk):              https://bugs.php.net/fix.php?id=62528&r=trysnapshottrunk
Fixed in SVN:                        https://bugs.php.net/fix.php?id=62528&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=62528&r=needdocs
Fixed in release:                    https://bugs.php.net/fix.php?id=62528&r=alreadyfixed
Need backtrace:                      https://bugs.php.net/fix.php?id=62528&r=needtrace
Need Reproduce Script:               https://bugs.php.net/fix.php?id=62528&r=needscript
Try newer version:                   https://bugs.php.net/fix.php?id=62528&r=oldversion
Not developer issue:                 https://bugs.php.net/fix.php?id=62528&r=support
Expected behavior:                   https://bugs.php.net/fix.php?id=62528&r=notwrong
Not enough info:                     https://bugs.php.net/fix.php?id=62528&r=notenoughinfo
Submitted twice:                     https://bugs.php.net/fix.php?id=62528&r=submittedtwice
register_globals:                    https://bugs.php.net/fix.php?id=62528&r=globals
PHP 4 support discontinued:          https://bugs.php.net/fix.php?id=62528&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62528&r=dst
IIS Stability:                       https://bugs.php.net/fix.php?id=62528&r=isapi
Install GNU Sed:                     https://bugs.php.net/fix.php?id=62528&r=gnused
Floating point limitations:          https://bugs.php.net/fix.php?id=62528&r=float
No Zend Extensions:                  https://bugs.php.net/fix.php?id=62528&r=nozend
MySQL Configuration Error:           https://bugs.php.net/fix.php?id=62528&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#171867) next »