Bug #53960 [Com]: "Invalid parameter number" for multiple params equals in query
| From: | baptx dot is at gmail dot com | Date: | Tue, 26 Jun 2012 11:56:21 +0000 |
| Subject: | Bug #53960 [Com]: "Invalid parameter number" for multiple params equals in query | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171534@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53960&edit=1
ID: 53960
Comment by: baptx dot is at gmail dot com
Reported by: contato at andersonfraga dot net
Summary: "Invalid parameter number" for multiple params
equals in query
Status: Not a bug
Type: Bug
Package: PDO related
Operating System: Windows
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
I've got this problem too, it's because of the PDO::ATTR_EMULATE_PREPARES => false
parameter! It seems native prepared statements don't allow the same names in one SQL query...
Previous Comments:
------------------------------------------------------------------------
[2011-05-11 13:22:23] contato at andersonfraga dot net
Okay then...
Could put some 'warning' in the doc? Please ... ;)
------------------------------------------------------------------------
[2011-05-11 11:05:37] johannes@php.net
The old behavior is clearly wrong. You have explicit names and they are ignored....
------------------------------------------------------------------------
[2011-05-10 17:58:00] contato at andersonfraga dot net
Anyway...
I think it should work, right?
'Even more because' it works in 5.2.14..
------------------------------------------------------------------------
[2011-05-10 10:03:11] uw@php.net
SQL - 2x hash_1:
AND (NOME_CLIENTE LIKE :hash_1
OR ENDERECO_CLIENTE LIKE :hash_1)
PHP bind - 1x hash_1, 1x hash_2:
$statement->execute(Array(
':hash_1' => '%Anderson%',
':hash_2' => 0,
------------------------------------------------------------------------
[2011-02-08 17:27:49] contato at andersonfraga dot net
Description:
------------
This error is occurring when I use the same parameter several times in the query.
In PHP 5.2.14, using Gentoo, it works perfectly. Already in versions 5.3.0 and 5.3.3 (using Windows
on both), returns an exception.
Bug or 'feature'?
Test script:
---------------
<?php
try {
$dbh = new PDO('mysql:/*irrelevant*/', Array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
));
$select = "SELECT * FROM PR_CLIENTE
WHERE DELETADO = 'N'
AND (NOME_CLIENTE LIKE :hash_1
OR ENDERECO_CLIENTE LIKE :hash_1)
ORDER BY ID_CLIENTE DESC
LIMIT :hash_2;";
$statement = $dbh->prepare($select);
$statement->execute(Array(
':hash_1' => '%Anderson%',
':hash_2' => 0,
));
$fetch = $statement->fetchAll(PDO::FETCH_ASSOC);
print_r($fetch);
}
catch(PDOException $e) {
print_r($e->getMessage());
}
?>
Expected result:
----------------
Array
(
[0] => Array
(
[ID_CLIENTE] => 29
(...)
)
)
Actual result:
--------------
SQLSTATE[HY093]: Invalid parameter number
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53960&edit=1