php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47009 PDO Mysql: can't handle commented out lines with bound params
Submitted: 2009-01-05 15:34 UTC Modified: 2009-05-03 01:00 UTC
From: andrew at ajohnstone dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.2.8 OS: fedora
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrew at ajohnstone dot com
New email:
PHP Version: OS:

 

 [2009-01-05 15:34 UTC] andrew at ajohnstone dot com
Description:
------------
databaseException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Can't handle commented out lines with bound params

Reproduce code:
---------------
SELECT 
  *
FROM 
  mapping_outlets mo
  JOIN media_outlets USING(mapping_outlets_id)
WHERE
  -- mo.mapping_outlets_id = ?
  mo.media_outlets_id = ?
GROUP BY ml.name
ORDER BY NULL
LIMIT 500

Expected result:
----------------
Ignore the commented outline.

Actual result:
--------------
databaseException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-05 22:36 UTC] felipe@php.net
I can't reproduce it using sqlite.

<?php

$x = new pdo('sqlite::memory');
$x->query('create table if not exists foo (x int)');
$x->query('insert into foo values (1)');
$x->query('insert into foo values (2)');
$y = $x->prepare('select x from foo 
where 
	-- x = ?
	x = ?');
var_dump($y->execute(array(2)));
var_dump($y->fetch());
var_dump($y->errorInfo());




bool(true)
array(2) {
  ["x"]=>
  string(1) "2"
  [0]=>
  string(1) "2"
}
array(1) {
  [0]=>
  string(5) "00000"
}

 [2009-01-05 22:44 UTC] felipe@php.net
Which SGBD are you using?
 [2009-01-06 11:13 UTC] johannes@php.net
I'm quite sure this is a problem with PS emulation, I have no test system at hand ...

Not sue how to handle it in our parser:The SQL standard wants, afaik, a space behind the --, MySQL fr instance doesn't need it.Additionally the same problem should exist with /* */ comments, which are implemented in different way, too (MySQL need no */)

Following the standard might still break stuff, not following the standard might break other case, making it driver dependent will give a mess...
 [2009-01-06 14:32 UTC] andrew at ajohnstone dot com
Thanks for the quick response, I should have stated this was using MySQL PDO driver.
 [2009-04-25 15:25 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2009-05-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 07:01:33 2025 UTC