|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81053 PDO quote method gives invalid result with single quotes inside string
Submitted: 2021-05-19 14:42 UTC Modified: 2021-05-21 14:15 UTC
From: madis at creditinfo dot ee Assigned:
Status: Open Package: PDO_INFORMIX (PECL)
PHP Version: 8.0.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
33 - 9 = ?
Subscribe to this entry?

 [2021-05-19 14:42 UTC] madis at creditinfo dot ee
The PDO quote method for Informix escapes single quotes inside string with a backslash which is invalid. A single quote should be escaped with another single quote ('TEST\'N%' is incorrect and breaks the query while 'TEST''N%' works).

Test script:
$pdo = new PDO();
$string = "TEST'N";
$search_string = $pdo->quote($string . "%");
$sql = "SELECT * FROM companies WHERE UPPER(name) LIKE $search_string LIMIT 1";
$query = $pdo->prepare($sql);
$result = $query->fetchAll(PDO::FETCH_ASSOC);

Expected result:
No errors

Actual result:
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: -11060 [Informix][Informix ODBC Driver]General error.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-05-21 14:15 UTC]
I don't know about INFORMIX, but that escaping[1] looks like MySQL

[1] <>
 [2021-06-04 09:15 UTC] madis at creditinfo dot ee
When stumbling on the problem I did some research and found information on, but overall I haven't dived into this enough to determine if escaping everything else works properly.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 02:01:28 2024 UTC