Skip to content

pdo_pgsql constructor behavior differs from documentation #12423

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

Closed
SakiTakamachi opened this issue Oct 12, 2023 · 0 comments
Closed

pdo_pgsql constructor behavior differs from documentation #12423

SakiTakamachi opened this issue Oct 12, 2023 · 0 comments

Comments

@SakiTakamachi
Copy link
Member

Description

The following code:

<?php
/*
correct credentials
user: p_user
pass: p_pass
*/

$db = new PDO(
    'pgsql:host=<host>;port=5432;dbname=db;user=p_user;password=p_pass', // my env
    'hoge',
    'fuga'
);

Resulted in this output:

// Connects to DB without any errors

But I expected this output instead:

Fatal error: Uncaught PDOException: SQLSTATE[08006] [7] connection to server at "<host>" (<host IP>), port 5432 failed: FATAL:  no pg_hba.conf entry for host "<client IP>", user "hoge", database "db", SSL encryption
connection to server at "<host>" (<host IP>), port 5432 failed: FATAL:  no pg_hba.conf entry for host "<client IP>", user "hoge", database "db", no encryption in <path to file>:8
Stack trace:
#0 <path to file>(8): PDO->__construct('pgsql:host=<host>.....', 'hoge', Object(SensitiveParameterValue))
#1 {main}
  thrown in <path to file> on line 8

This result means that if both the DSN and the argument are given different credentials, the DSN's credentials are ignored and the argument's credentials are used.

This behavior differs from what is described in the documentation.
https://www.php.net/manual/en/ref.pdo-pgsql.connection.php

Also, pdo_odbc can similarly pass credentials to both DSN and arguments, but pdo_odbc gives priority to DSN. Based on these things, I think that the behavior of pdo_pgsql should be modified.

PHP Version

At least php5.6+

Operating System

any

nicolas-grekas added a commit to symfony/symfony that referenced this issue Nov 6, 2023
…for PDO PostgreSQL (HypeMC)

This PR was merged into the 5.4 branch.

Discussion
----------

[Cache][HttpFoundation][Lock] Fix empty username/password for PDO PostgreSQL

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Currently [pdo_pgsql has a bug](php/php-src#12423) where the username & password arguments have precedence over the DSN, even thought [according to the docs](https://www.php.net/manual/en/ref.pdo-pgsql.connection.php) it should be the other way. This was recently fixed on PHP's side, but it [won't be available till 8.4](php/php-src#12424).

Since the bug is not present when the values passed are `null`, which are the default argument values anyway, this PR changes the default values of the properties to match.

Commits
-------

534c34c [Cache][HttpFoundation][Lock] Fix empty username/password for PDO PostgreSQL
symfony-splitter pushed a commit to symfony/cache that referenced this issue Nov 6, 2023
…for PDO PostgreSQL (HypeMC)

This PR was merged into the 5.4 branch.

Discussion
----------

[Cache][HttpFoundation][Lock] Fix empty username/password for PDO PostgreSQL

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Currently [pdo_pgsql has a bug](php/php-src#12423) where the username & password arguments have precedence over the DSN, even thought [according to the docs](https://www.php.net/manual/en/ref.pdo-pgsql.connection.php) it should be the other way. This was recently fixed on PHP's side, but it [won't be available till 8.4](php/php-src#12424).

Since the bug is not present when the values passed are `null`, which are the default argument values anyway, this PR changes the default values of the properties to match.

Commits
-------

534c34cb79 [Cache][HttpFoundation][Lock] Fix empty username/password for PDO PostgreSQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant