Bug #71447 [Asn->Csd]: an query may return bad result or error "Invalid parameter number"
| From: | mbeccati@php.net | Date: | Mon, 04 Apr 2016 22:12:00 +0000 |
| Subject: | Bug #71447 [Asn->Csd]: an query may return bad result or error "Invalid parameter number" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200359@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71447&edit=1
ID: 71447
Updated by: mbeccati@php.net
Reported by: skrol29forum+bugsphp at gmail dot com
Summary: an query may return bad result or error "Invalid
parameter number"
-Status: Assigned
+Status: Closed
Type: Bug
Package: PDO PgSQL
Operating System: Windows 10, Debian Cid
PHP Version: 5.6.17
Assigned To: mbeccati
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of mbeccati
Revision: http://git.php.net/?p=php-src.git;a=commit;h=30925cd49826c59ea8459a24bcb24d47c2ce562d
Log: Fixed bug #71447 (Quotes inside comments not properly handled)
Previous Comments:
------------------------------------------------------------------------
[2016-01-25 16:10:45] skrol29forum+bugsphp at gmail dot com
Description:
------------
Depending to a comment in the SQL query, PDO will run it correctly or return an error, or even a
wrong result.
Run the test script and an error will raise while the query contains actually no PDO parameters.
Then if you simply delete the character single-quote (replace "that's strange" with
"thats strange") in the comment of the SQL query there will be no error.
--------------
More dramatic:
--------------
Replace:
$pdo->query($sql_1, PDO::FETCH_NUM);
With:
$pdo->query($sql_2, PDO::FETCH_NUM);
in order to run the second query.
Take car to previously create the table and the row using the small SQL script at the head of the
script.
In this case, there is no error, but the query returns a wrong result (NULL instead of
'8000'). If you delete the single-quote in the comment, then the result is correct.
The bug occurs with Windows 10 and Debian Cid with PHP 5.6.17 but also with versions 5.6.16 and
5.6.15. Not tested on PHP 7.
The bug does not occurs with PHP 5.4.3.
I've tested a similar query with PDO-MySQL and there is no error.
---------
PDO version with PHP 5.6.17:
PostgreSQL(libpq) Version 9.4.1
Module version 1.0.2
Revision $Id: 93432550a76a2298959ec74f40d65c7195a82ad2 $
---------
Test script:
---------------
/*
Database structure for query #2
CREATE SCHEMA _test;
CREATE TABLE _test.t_test (prms character varying(255));
INSERT INTO _test.t_test (prms) VALUES ('{"radius":8000}');
*/
// connection to the PostgreSQL database
$pdo = new PDO("pgsql:dbname=mydb;host=myhost", 'myusername',
'mypassword');
$sql_1 = "
SELECT -- that's strange
SUBSTRING( '{\"radius\":8000}'::text FROM
'(?:\"radius\":)([\d\.]*)') AS zzz";
$sql_2 = "
SELECT -- that's strange
SUBSTRING( prms::text FROM '(?:\"radius\":)([\d\.]*)') AS zzz
FROM _test.t_test";
$rs = $pdo->query($sql_1, PDO::FETCH_NUM);
$rec = $rs->fetch();
var_export($rec);
Expected result:
----------------
array (
0 => '8000',
)
Actual result:
--------------
Query #1 returns :
« PDO::query(): SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
in ... »
Query #2 returns :
array (
0 => NULL,
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71447&edit=1