-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Closed as not planned
Copy link
Description
Description
Hey there, hopefully I've missed something:
Introduced with the RFC https://wiki.php.net/rfc/pdo_escape_placeholders, and later by #4217, the question mark escaping RFC give this precision:
The parsing of the “??” character sequence within queries is going to change, but only when they are outside of literal strings or comments. Since such character sequence isn't normally valid SQL syntax, no BC break is expected.
But does this means it is still impossible to build a jsonpath string parameter using PDO?
By example, the following code:
<?php
$user = 'XXXX';
$pass = 'XXXX';
$dbh = new PDO('pgsql:host=localhost;dbname=test', $user, $pass);
$stmt = $dbh->prepare("SELECT jsonb_path_query_array('[\"abc\", \"abd\", \"aBdC\", \"abdacb\", \"babc\"]'::jsonb, '$[*] ?? (@ like_regex ? flag \"i\")');");
$value = '^ab.*c';
$stmt->bindParam(1, $value);
$stmt->execute();
Resulted in this output:
PHP Fatal error: Uncaught PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "?" of jsonpath input
LINE 1: ...["abc", "abd", "aBdC", "abdacb", "babc"]'::jsonb, '$[*] ?? (...
^ in /home/stacy/tmp/pdophp/index.php:12
Stack trace:
#0 /home/stacy/tmp/pdophp/index.php(12): PDOStatement->execute()
#1 {main}
thrown in /home/stacy/tmp/pdophp/index.php on line 12
PHP Version
8.4.2
Operating System
Alpine Linux