Skip to content

Instantly share code, notes, and snippets.

@youkidearitai
Created July 7, 2023 14:14
Show Gist options
  • Save youkidearitai/eb7d57001810bf9410f9bf6d231d15b2 to your computer and use it in GitHub Desktop.
Save youkidearitai/eb7d57001810bf9410f9bf6d231d15b2 to your computer and use it in GitHub Desktop.
--TEST--
GH-11587 Fixed the condition for result set values to be of native type, making it compatible with previous versions. #11616
--EXTENSIONS--
pdo_mysql
--SKIPIF--
<?php
if (!extension_loaded('mysqli') && !extension_loaded('mysqlnd')) {
/* Need connection to detect library version */
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
MySQLPDOTest::skip();
}
?>
--FILE--
<?php
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
$db = MySQLPDOTest::factory();
$db->exec("DROP TABLE IF EXISTS test");
$createTestTable = <<<SQL
CREATE TABLE test(
id INT,
`float_col` float(3,2) DEFAULT NULL,
`double_col` double(3,2) DEFAULT NULL,
`decimal_col` decimal(3,2) DEFAULT NULL
)
SQL;
$db->exec($createTestTable);
$insertTestTable = <<<SQL
INSERT INTO test(id, float_col, double_col, decimal_col) VALUES(1, 2.60, 3.60, 4.60)
SQL;
$db->exec($insertTestTable);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
$results = $db->query("SELECT * FROM test");
foreach ($results as $result) {
var_dump($result);
}
echo "done!";
?>
--CLEAN--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--EXPECTF--
array(8) {
["id"]=>
string(1) "1"
[0]=>
string(1) "1"
["float_col"]=>
string(4) "2.60"
[1]=>
string(4) "2.60"
["double_col"]=>
string(4) "3.60"
[2]=>
string(4) "3.60"
["decimal_col"]=>
string(4) "4.60"
[3]=>
string(4) "4.60"
}
done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment