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

Keep pdo mysql adapter fetch digit field type BC with php <= 8.0 #324

Merged
merged 3 commits into from
Feb 22, 2023

Conversation

hungtrinh
Copy link

@hungtrinh hungtrinh commented Feb 14, 2023

Close #323

Task done

  • Specification PDO fetch mysql int type will return php 'int' string instead of php int type (test case)
    public function testGivenBeforePhp81WhenFetchDataOnDigitFieldThenPdoMysqlWillReturnStringDigit()
    {
    $params = $this->_util->getParams();
    $db = Zend_Db::factory($this->getDriver(), $params);
    $db->getConnection();
    $select = $this->_db->select();
    $select->from('zfproducts');
    $stmt = $this->_db->query($select);
    $products = $stmt->fetchAll();
    $productId = $products[0]['product_id'] ?? '-1';
    $this->assertSame(
    '1',
    $productId,
    "BC with php < 8.1, fetch numeric field type will return 'digit' string instead of int or float type in php >= 8.1.\nSee: https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql"
    );
    }

    Fail since php 8.1 https:/hungtrinh/zf1-future/actions/runs/4171264561/jobs/7221025095#step:7:436
  • Specification PDO mysql adapter will init connection with driver_options PDO::ATTR_STRINGIFY_FETCHES is on (test case)
    /**
    * https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql
    * @inheritDoc
    */
    public function testAdapterZendConfigEmptyDriverOptions()
    {
    $params = $this->_util->getParams();
    $params['driver_options'] = [];
    $params = new Zend_Config($params);
    $db = Zend_Db::factory($this->getDriver(), $params);
    $db->getConnection();
    $config = $db->getConfig();
    if (PHP_VERSION_ID >= 80100) {
    $this->assertEquals([PDO::ATTR_STRINGIFY_FETCHES => true], $config['driver_options']);
    } else {
    $this->assertSame([], $config['driver_options']);
    }
    }

    Fail since php 8.1 https:/hungtrinh/zf1-future/actions/runs/4171266288/jobs/7221028465#step:7:445
  • Production code fulfil 2 specifications above
    if (PHP_VERSION_ID >= 80100) {
    // ensure $config['driver_options'] is an array
    $this->_config['driver_options'] = $this->_config['driver_options'] ?? [];
    if (!isset($this->_config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES])) {
    $this->_config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES] = true;
    }
    }

    2 Spec done https:/hungtrinh/zf1-future/actions/runs/4171334806/jobs/7221167701#step:7:248

@hungtrinh hungtrinh changed the title Close #323 - Keep pdo mysql adapter fetch digit field type BC since php 8.1 Close #323 - Since php 8.1, Keep pdo mysql adapter fetch digit field type BC with php <= 8.0 Feb 14, 2023
@hungtrinh hungtrinh changed the title Close #323 - Since php 8.1, Keep pdo mysql adapter fetch digit field type BC with php <= 8.0 Close #323 - Keep pdo mysql adapter fetch digit field type BC with php <= 8.0 Feb 14, 2023
@hungtrinh
Copy link
Author

Mr @glensc could you please review this PR, thanks

@glensc glensc changed the title Close #323 - Keep pdo mysql adapter fetch digit field type BC with php <= 8.0 Keep pdo mysql adapter fetch digit field type BC with php <= 8.0 Feb 22, 2023
@glensc
Copy link
Collaborator

glensc commented Feb 22, 2023

this looks similar to #320

@glensc glensc merged commit 640a0eb into Shardj:master Feb 22, 2023
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.

Zend_Db_Adapter_Pdo_Mysql fetch digit field type - BC break since php 8.1
3 participants