Skip to content

Commit

Permalink
Merge pull request #320 from hungtrinh/pdo-sqlite-keep-bc-since-php81
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc authored Feb 9, 2023
2 parents 15c78f3 + e5fc4ea commit 2ae18be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions library/Zend/Db/Adapter/Pdo/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public function __construct(array $config = [])
$this->_config['username'] = null;
$this->_config['password'] = null;

if (PHP_VERSION_ID >= 80100) {
// ensure $config['driver_options'] is an array
$config['driver_options'] = $config['driver_options'] ?? [];
if (!isset($config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES])) {
$config['driver_options'][PDO::ATTR_STRINGIFY_FETCHES] = true;
}
}

return parent::__construct($config);
}

Expand Down
22 changes: 22 additions & 0 deletions tests/Zend/Db/Adapter/Pdo/SqliteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,26 @@ public function testAdapterQuoteNullByteCharacter()
$value = $this->_db->quote($string);
$this->assertEquals("'1\\000'", $value);
}

/**
* https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.sqlite
* @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->assertEquals([], $config['driver_options']);
}
}
}

0 comments on commit 2ae18be

Please sign in to comment.