Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdo_pgsql: question marks seen as parameter placeholders in dollar-quoted string #14244

Open
outtersg opened this issue May 15, 2024 · 2 comments

Comments

@outtersg
Copy link
Contributor

outtersg commented May 15, 2024

Description

Dollar-quoting is a PostgreSQL way of quoting strings, and "no characters inside a dollar-quoted string are ever escaped" (see the official docs).

pdo_pgsql however sees ? as parameter placeholders (and replaces them with $1, $2, etc., when not emulating prepares which is the default mode).

See attached test case bug14244.phpt

PHP Version

PHP 8.2.1

@outtersg
Copy link
Contributor Author

outtersg commented May 15, 2024

As seen in SO "How to prevent PDO from interpreting a question mark as a placeholder?", there exists workarounds.
However:

  • doubling the ?s makes the SQLs PDO-specific
  • ATTR_EMULATE_PREPARES is counter-intuitive, because "emulating" means "an additional layer between high- and low-level", while we just want "removing any intermediary layer to push our SQL as raw as possible to the DB".

Another thought that complicates solving :-\ is that any solution that would remove the undesired translation would break the SQL of people relying on the first workaround.

So maybe this will end in a "Won't fix", but with a clarification on the doc stating which combination of options (ATTR_EMULATE_PREPARES) will give pdo_pgsql the most direct-to-DB behaviour (and what to expect regarding other surprises. Perhaps a big table listing snippets of SQL, and for each combination of options what SQL gets effectively passed to the DB).

@MorganLOCode
Copy link

This is somewhat on the radar as a side-effect of this:
https://wiki.php.net/rfc/pdo_driver_specific_parsers
with a bit of discussion on the mailing list which may provide some food for thought.

mbeccati added a commit that referenced this issue May 20, 2024
Allow "??" in dollar quoted strings for backwards compatibility,
as it was a viable workaround to insert question marks without them
being parsed as placeholders.

Add a deprecation notice to tell that the escape is no longer
necessary within dollar quotes and that its usage is deprecated.

Ref bug #14244
mbeccati added a commit to mbeccati/php-src that referenced this issue May 21, 2024
Allow "??" in dollar quoted strings for backwards compatibility,
as it was a viable workaround to insert question marks without them
being parsed as placeholders.

Add a deprecation notice to tell that the escape is no longer
necessary within dollar quotes and that its usage is deprecated.

Ref bug php#14244
mbeccati added a commit to mbeccati/php-src that referenced this issue May 31, 2024
Allow "??" in dollar quoted strings for backwards compatibility,
as it was a viable workaround to insert question marks without them
being parsed as placeholders.

Add a deprecation notice to tell that the escape is no longer
necessary within dollar quotes and that its usage is deprecated.

Ref bug php#14244
mbeccati added a commit to mbeccati/php-src that referenced this issue May 31, 2024
Allow "??" in dollar quoted strings for backwards compatibility,
as it was a viable workaround to insert question marks without them
being parsed as placeholders.

Add a deprecation notice to tell that the escape is no longer
necessary within dollar quotes and that its usage is deprecated.

Ref bug php#14244
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants