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

[5.8] Binding value as PDO::PARAM_INT has different behaviour in PHP 7.2 + MysqlConnection #28379

Closed
wants to merge 1 commit into from

Conversation

frederikbosch
Copy link
Contributor

@frederikbosch frederikbosch commented May 1, 2019

When binding a value against a MySQL PDO statement, the behaviour between PHP 7.1 and PHP 7.2 differs. When you bind a value as integer while passing a float, this was no problem with PHP7.1. However, it became a problem in PHP7.2.

The problem is when executing the following. It inserts 0.5 in PHP7.1, and 0 in PHP7.2. I have tested this against MariaDB (10.1 and 10.2), not against MySQL. Another person also found difference in behaviour: https://stackoverflow.com/questions/54413798/pdoparam-int-behaviour-in-php-7-1-php-7-2.

$stmt = $pdo->prepare('INSERT INTO tbl (val) VALUES (?)');
$stmt->bindValue(1, 0.5, PDO::PARAM_INT);

This PR fixes that issue. Moreover, it includes tests for the possible PDO::PARAM_XXX used my the bindValue method in MysqlConnection.

Because I am wondering if this is intended behaviour of PHP, I also opened a PHP bug report for it. Nonetheless, I think that using PDO::PARAM_STR is better for floating points than using PDO::PARAM_INT.

@frederikbosch
Copy link
Contributor Author

If someone wants to test this (e.g. on a MySQL instead of MariaDB server), you can use the following script.

@frederikbosch
Copy link
Contributor Author

frederikbosch commented May 1, 2019

Hmm, I just found out that this caused a pain already and has been discussed multiple times. I have learned so far that PDO::PARAM_INT is used because of JSON comparison (#16069 and #16063) and that other people already submitted issues for the same problem I have #23850, #27596, #26817 and #25818.

@frederikbosch
Copy link
Contributor Author

The commit in the PHP source that is causing is the following one and this is the related bug report.

@taylorotwell
Copy link
Member

Don't think we can do this for reasons noted in other issues. I assume you are using EMULATE_PREPARES?

@GrahamCampbell GrahamCampbell changed the title Binding value as PDO::PARAM_INT has different behaviour in PHP 7.2 + MysqlConnection [5.8] Binding value as PDO::PARAM_INT has different behaviour in PHP 7.2 + MysqlConnection Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants