php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45169 Some error messages are uninformative
Submitted: 2008-06-04 11:24 UTC Modified: 2021-08-27 12:59 UTC
Votes:18
Avg. Score:4.3 ± 0.8
Reproduced:13 of 13 (100.0%)
Same Version:6 (46.2%)
Same OS:2 (15.4%)
From: ian dot lewis at mediatel dot co dot uk Assigned:
Status: Open Package: PDO related
PHP Version: 5.2.6 OS: Linux Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ian dot lewis at mediatel dot co dot uk
New email:
PHP Version: OS:

 

 [2008-06-04 11:24 UTC] ian dot lewis at mediatel dot co dot uk
Description:
------------
The error message is given below.

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in xxx.php

It would be - extremely - helpful if the error message contained a list of the matched tokens or some information on where the token substitution failed.



Reproduce code:
---------------
$query = "SELECT *
FROM example_table et
WHERE start_date BETWEEN ':sStartDate' AND ':sEndDate'
 AND user_id = :iId"

<snip prepare statement>

$sStatement->bindParam(':iId',         $iUserId,      PDO::PARAM_INT);
$sStatement->bindParam(':sStartDate',  $sStartDate,    PDO::PARAM_STR);
$sStatement->bindParam(':sEndDate',    $sEndDate,      PDO::PARAM_STR);
$sStatement->execute();

The error PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in xxx.php

Expected result:
----------------
Expect to see either no error because it worked or a message such as

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in xxx.php. Cannot find   token :sStartDate

Actual result:
--------------
PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in xxx.php



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-24 10:43 UTC] lapo at lapo dot it
You problem is probably that you used "'" for bound strings when they 
should not be used (and thus they were considered constant strings), but 
I do agree on the issue that the error could be more informative.
 [2011-04-08 21:04 UTC] jani@php.net
-Summary: PDO Some error messages are uninformative +Summary: Some error messages are uninformative -Package: Feature/Change Request +Package: PDO related
 [2021-08-27 12:59 UTC] cmb@php.net
> It would be - extremely - helpful if the error message contained
> a list of the matched tokens or some information on where the
> token substitution failed.

While that probably can be done for emulated prepares, it cannot
be done for native prepares (because these are not processed by
PHP, so we rely on what the server reports), and it seems to me
that the latter are more widely used.

Anyhow, 18 upvotes, so I'm leaving this open.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 01:01:28 2024 UTC