[php-src] Issue #13958: PDO_PGSQL - PDOException: SQLSTATE[HY093]: Invalid parameter number: :b
| From: | mvorisek | Date: | Sat, 13 Apr 2024 21:03:28 +0000 |
| Subject: | [php-src] Issue #13958: PDO_PGSQL - PDOException: SQLSTATE[HY093]: Invalid parameter number: :b | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246755@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13958
Author: mvorisek
### Description
The following code:
```php
<?php
$pdo = new PDO('pgsql:host=127.0.0.1;dbname=xxx', 'user', 'pass');
$sql = <<<'EOF'
select :a x, '\' x2
EOF;
$statement = $pdo->prepare($sql);
$statement->bindValue('a', 'va');
$statement->execute();
$res = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($res);
$sql = <<<'EOF'
select :a x, '\' x2, :b y, '\' y2
EOF;
$statement = $pdo->prepare($sql);
$statement->bindValue('a', 'va');
$statement->bindValue('b', 'vb');
$statement->execute();
$res = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($res);
```
Resulted in this output:
```
array(1) {
[0]=>
array(2) {
["x"]=>
string(2) "va"
["x2"]=>
string(1) "\"
}
}
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: :b in
C:\...\repro.php on line 20
array(0) {
}
```
But I expected this output instead:
```
array(1) {
[0]=>
array(2) {
["x"]=>
string(2) "va"
["x2"]=>
string(1) "\"
}
}
array(1) {
[0]=>
array(4) {
["x"]=>
string(2) "va"
["x2"]=>
string(1) "\"
["y"]=>
string(2) "vb"
["y2"]=>
string(1) "\"
}
}
```
'\' is causing the issue - but it is absolutely correct string syntax.
It seems php-src parses the SQL using the old mode (default until PostgreSQL 9.1) - https://www.postgresql.org/docs/current/runtime-config-compatible.html#GUC-STANDARD-CONFORMING-STRINGS.
### PHP Version
any (tested 7.4 and 8.3)
### Operating System
any (tested Windows and linux)