|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-09-13 12:54 UTC] mnvx at yandex dot ru
Description: ------------ Script below returns one record (incorrect) instead of two (expected). This script executed directly in PostgreSQL console returns two rows (correct). For thinking. After replacing 'CHACTECHNOLOGICO\\' to 'CHACTECHNOLOGICO' OR "?" to "-" in both places script returns two records (it is correct). Discussion on stackoverflow: https://stackoverflow.com/questions/57858915 Test script: --------------- <?php $pdo = new \PDO('pgsql:host=localhost;dbname=postgres', 'postgres', 'postgres'); $sql = <<<SQL SELECT * FROM ( SELECT 'CHAC TECHNOLOG*' as alias UNION SELECT 'KINDERY LIGHTING SALES DE?T*' ) m JOIN ( SELECT 'CHACTECHNOLOGICO\\' as ie_clean UNION SELECT 'KINDERYLIGHTINGSALESDEPT' as ie_clean ) t ON t.ie_clean ILIKE REPLACE(REPLACE(REPLACE(m.alias, '*', '%'), '?', '_'), ' ', '') ORDER BY ie_clean; SQL; echo $sql . PHP_EOL . PHP_EOL; $stmt = $pdo->query($sql); print_r($stmt->fetchAll(PDO::FETCH_ASSOC)); Expected result: ---------------- Array ( [0] => Array ( [alias] => CHAC TECHNOLOG* [ie_clean] => CHACTECHNOLOGICO\ ) [1] => Array ( [alias] => KINDERY LIGHTING SALES DE?T* [ie_clean] => KINDERYLIGHTINGSALESDEPT ) ) Actual result: -------------- Array ( [0] => Array ( [alias] => CHAC TECHNOLOG* [ie_clean] => CHACTECHNOLOGICO\ ) ) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 14:00:01 2025 UTC |
The bug is there, but returning less rows is just a side effect of the complex query with replace. I think this smaller query better highlights the problem: SELECT 'foo\' AS a, '?' AS b PDO has a single parser for all the drivers, which detects "'foo\' AS a, '" being a string, thus the ? is outside and replaced as $1 placeholder, so the result is: Array ( [0] => Array ( [x] => foo\ [y] => $1 ) ) FYI I have a prototype fix in the works, but it requires allowing drivers to use custom parsers, which most likely will require an RFC.