|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-07-29 17:48 UTC] untold69 at hotmail dot com
Description:
------------
Using PDO to prepare and then execute a statement that queries for a backslash and
then a question mark sequentially in two columns generates a warning.
Test script:
---------------
$pdo = new PDO("mssql:dbname=mydb;host=myhost", "myuser", "mypassword");
$stmt = $pdo->prepare("SELECT * FROM table WHERE column1 = '\' AND column2 = '?'");
$result = $stmt->execute();
Expected result:
----------------
Array or false.
Actual result:
--------------
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid
parameter number: no parameters were bound in ...
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
The question mark is surrounded by quotes and so should be used as a literal value to query the table column, not as a parameter placeholder. The exact same SQL statement executes fine when using PDO::query, e.g. $result = $pdo->query("SELECT * FROM table WHERE column1 = '\' AND column2 = '?'");The problem is also specific to the order in which the parameters appear in the statement, for instance this also executes without problem: $stmt = $pdo->prepare("SELECT * FROM table WHERE column1 = '?' AND column2 = '\'"); $result = $stmt->execute(); So I assume the issue lies in the way PDO parses the SQL statement when preparing.