Skip to content

Incorrect NUMERIC value returned from Firebird PDO query in PHP 8.1 #9971

Closed

Description

@clarumedia

Description

The following code:

//$pdo already connected with no dialect specified (Defaults to 3 ?)

$sql="SELECT SOME_INDEX,
SOME_NUMERIC_FIELD, 
CAST (SOME_NUMERIC_FIELD AS VARCHAR(255)) AS SOME_NUMERIC_FIELD_STRING
FROM MYTABLE WHERE SOME_INDEX='1234' ";

$objPDOStatement=$pdo->query($sql);

foreach($objPDOStatement as $arrRow){
	print_r($arrRow);
	exit;
}

Resulted in this output in PHP 8.1.12 :

Array
(
    [SOME_INDEX] => 1234
    [0] => 1234
    [SOME_NUMERIC_FIELD] => 0.00000000
    [1] => 0.00000000
    [SOME_NUMERIC_FIELD_STRING] => 1.00000000            
    [2] => 1.00000000            
)

But I expected this output instead as per PHP 7.4:

Array
(
    [SOME_INDEX] => 1234
    [0] => 1234
    [SOME_NUMERIC_FIELD] => 1.00000000
    [1] => 1.00000000
    [SOME_NUMERIC_FIELD_STRING] => 1.00000000            
    [2] => 1.00000000            
)


Both report LI-V6.3.5.33220 Firebird 3.0 from a call to
$pdo->getAttribute(PDO::ATTR_CLIENT_VERSION)

Makes no difference if I set
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);

PHP Version

PHP 8.1.12

Operating System

Ubuntu 20.04

Activity

  1. changed the title [-]Incorrect NUMERIC value returned from PDO query in PHP 8.1[/-] [+]Incorrect NUMERIC value returned from Firebird PDO query in PHP 8.1[/+] on Nov 18, 2022
  2. cmb69 commented on Nov 18, 2022

    @cmb69
    Member

    Hmm, there is https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt, which queries a NUMERIC(15,2) row, and that works (also locally for me).

    Can you please specify the exact table definition – ideally having a complete script which creates and fills the table, and then does the query, printing the resulting row via var_dump()?

  3. clarumedia commented on Nov 18, 2022

    @clarumedia
    Author

    Test Results for the script at https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt

    Additional comment added 19/11/2022: My apologies, I neglected to mention that I had to use "dialect=1;" to get the test to work in either PHP7.4 or 8.1.12. My previous scripts in PHP7.4 were only ever doing selects.
    "Metadata update statement is not allowed by the current database SQL dialect 1"

    PHP 7.4

    string(5) "-1.00"
    string(5) "-0.99"
    string(5) "-1.01"

    PHP 8.1.12 (php8.1-interbase 8.1.12-1+ubuntu20.04.1+deb.sury.org+1)

    string(4) "0.00"
    string(11) "20615843.02"
    string(12) "-10307921.51"

  4. hormus commented on Nov 19, 2022

    @hormus

    Hi @clarumedia please Test phpt code use pdo_firebird extension installed and enabled not interbase extension
    https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/skipif.inc
    https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/testdb.inc
    and https://github.com/php/php-src/blob/PHP-8.1/ext/pdo_firebird/tests/bug_64037.phpt

    the fix seems to me never came for the shortstop extension please @cmb69 can you confirm if you are not busy? Thank you

  5. cmb69 commented on Nov 19, 2022

    @cmb69
    Member

    string(4) "0.00"
    string(11) "20615843.02"
    string(12) "-10307921.51"

    This is seriously screwed. What's the version of your database server?

  6. clarumedia commented on Nov 19, 2022

    @clarumedia
    Author

    @cmb69

    print $dbh->getAttribute(PDO::ATTR_SERVER_INFO);

    PHP 7.4

    Server Version: Firebird/Windows/Intel/i386 (access method), version "WI-V2.0.1.12855 Firebird 2.0" Firebird/Windows/Intel/i386 (remote server), version "WI-V2.0.1.12855 Firebird 2.0/tcp (DBSERVERHOSTNAME)/P10" Firebird/Linux/AMD/Intel/x64 (remote interface), version "LI-V3.0.5.33220 Firebird 3.0/tcp (arm-lnx-1)/P10" on disk structure version 11.0

    PHP 8.1

    Server Version: Firebird/Windows/Intel/i386 (access method), version "WI-V2.0.1.12855 Firebird 2.0" Firebird/Windows/Intel/i386 (remote server), version "WI-V2.0.1.12855 Firebird 2.0/tcp (DBSERVERHOSTNAME)/P10" Firebird/Linux/AMD/Intel/x64 (remote interface), version "LI-V3.0.5.33220 Firebird 3.0/tcp (arm-lnx-1)/P10" on disk structure version 11.0

  7. 31 remaining items

  8. added a commit that references this issue on Nov 29, 2022
    a93ee2b
  9. cmb69 commented on Nov 29, 2022

    @cmb69
    Member

    Thanks for checking, @clarumedia!

    Looks like that's fixed it. :-)

    Interesting! So apparently the issue was "only" the ZEND_ASSUME(0) which caused a compiler "optimization" which lead to reading of uninitialized memory. I've just submitted a PR with a slightly simplified solution; maybe you can try that, too.

  10. clarumedia commented on Nov 29, 2022

    @clarumedia
    Author

    @cmb69

    Test results for your simplified fix: https://github.com/php/php-src/pull/10021/files

    Connecting with:firebird:dbname=localhost:/var/lib/firebird/3.0/data/second_database.fdb;dialect=1
    string(5) "-1.00"
    string(5) "-0.99"
    string(5) "-1.01"

    Looking good :-)

  11. added 2 commits that reference this issue on Nov 30, 2022
    44377c3
    e29ca36
  12. added a commit that references this issue on Nov 30, 2022
    7402d90
  13. clarumedia commented on Nov 30, 2022

    @clarumedia
    Author

    Thank you @cmb69 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions