diff --git a/ext/pdo_mysql/tests/gh-11587.phpt b/ext/pdo_mysql/tests/gh-11587.phpt new file mode 100644 index 0000000000000..524d8c8002a0b --- /dev/null +++ b/ext/pdo_mysql/tests/gh-11587.phpt @@ -0,0 +1,149 @@ +--TEST-- +GH-11587 PHP8.1: Fixed the condition for result set values to be of native type, making it compatible with previous versions. #11622 +--EXTENSIONS-- +pdo_mysql +--SKIPIF-- + +--FILE-- +exec('DROP TABLE IF EXISTS test'); + +$createTestTable = <<exec($createTestTable); + +$insertTestTable = <<exec($insertTestTable); + +// PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true +$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); +} + +// PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +// PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false; +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +// PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false +$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); +$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); +$results = $db->query('SELECT * FROM test'); +foreach ($results as $result) { + var_dump($result); +} + +echo 'done!'; +?> +--CLEAN-- + +--EXPECT-- +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" +} +array(8) { + ["id"]=> + int(1) + [0]=> + int(1) + ["float_col"]=> + float(2.6) + [1]=> + float(2.6) + ["double_col"]=> + float(3.6) + [2]=> + float(3.6) + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +array(8) { + ["id"]=> + string(1) "1" + [0]=> + string(1) "1" + ["float_col"]=> + string(3) "2.6" + [1]=> + string(3) "2.6" + ["double_col"]=> + string(3) "3.6" + [2]=> + string(3) "3.6" + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +array(8) { + ["id"]=> + int(1) + [0]=> + int(1) + ["float_col"]=> + float(2.6) + [1]=> + float(2.6) + ["double_col"]=> + float(3.6) + [2]=> + float(3.6) + ["decimal_col"]=> + string(4) "4.60" + [3]=> + string(4) "4.60" +} +done!