xref: /PHP-8.4/ext/pdo_mysql/tests/gh11587.phpt (revision 4bb75d56)
1--TEST--
2GH-11587 PHP8.1: Fixed the condition for result set values to be of native type, making it compatible with previous versions. #11622
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9MySQLPDOTest::skipNotMySQLnd();
10?>
11--FILE--
12<?php
13require_once __DIR__ . '/inc/mysql_pdo_test.inc';
14$db = MySQLPDOTest::factory();
15
16$createTestTable = <<<SQL
17CREATE TABLE test_11587(
18   id INT,
19  `float_col` FLOAT(3,2) DEFAULT NULL,
20  `double_col` DOUBLE(3,2) DEFAULT NULL,
21  `decimal_col` DECIMAL(3,2) DEFAULT NULL
22)
23SQL;
24
25$db->exec($createTestTable);
26
27$insertTestTable = <<<SQL
28INSERT INTO test_11587(id, float_col, double_col, decimal_col) VALUES(1, 2.60, 3.60, 4.60)
29SQL;
30
31$db->exec($insertTestTable);
32
33echo "PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true\n";
34$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
35$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
36$results = $db->query('SELECT * FROM test_11587');
37foreach ($results as $result) {
38    var_dump($result);
39}
40
41echo "\n";
42
43echo "PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false\n";
44$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
45$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
46$results = $db->query('SELECT * FROM test_11587');
47foreach ($results as $result) {
48    var_dump($result);
49}
50
51echo "\n";
52
53echo "PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true\n";
54$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
55$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
56$results = $db->query('SELECT * FROM test_11587');
57foreach ($results as $result) {
58    var_dump($result);
59}
60
61echo "\n";
62
63echo "PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false\n";
64$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
65$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
66$results = $db->query('SELECT * FROM test_11587');
67foreach ($results as $result) {
68    var_dump($result);
69}
70
71echo "\n";
72
73echo 'done!';
74?>
75--CLEAN--
76<?php
77require_once __DIR__ . '/inc/mysql_pdo_test.inc';
78$db = MySQLPDOTest::factory();
79$db->exec('DROP TABLE IF EXISTS test_11587');
80?>
81--EXPECT--
82PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = true
83array(8) {
84  ["id"]=>
85  string(1) "1"
86  [0]=>
87  string(1) "1"
88  ["float_col"]=>
89  string(4) "2.60"
90  [1]=>
91  string(4) "2.60"
92  ["double_col"]=>
93  string(4) "3.60"
94  [2]=>
95  string(4) "3.60"
96  ["decimal_col"]=>
97  string(4) "4.60"
98  [3]=>
99  string(4) "4.60"
100}
101
102PDO::ATTR_EMULATE_PREPARES = true, PDO::ATTR_STRINGIFY_FETCHES = false
103array(8) {
104  ["id"]=>
105  int(1)
106  [0]=>
107  int(1)
108  ["float_col"]=>
109  float(2.6)
110  [1]=>
111  float(2.6)
112  ["double_col"]=>
113  float(3.6)
114  [2]=>
115  float(3.6)
116  ["decimal_col"]=>
117  string(4) "4.60"
118  [3]=>
119  string(4) "4.60"
120}
121
122PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = true
123array(8) {
124  ["id"]=>
125  string(1) "1"
126  [0]=>
127  string(1) "1"
128  ["float_col"]=>
129  string(3) "2.6"
130  [1]=>
131  string(3) "2.6"
132  ["double_col"]=>
133  string(3) "3.6"
134  [2]=>
135  string(3) "3.6"
136  ["decimal_col"]=>
137  string(4) "4.60"
138  [3]=>
139  string(4) "4.60"
140}
141
142PDO::ATTR_EMULATE_PREPARES = false, PDO::ATTR_STRINGIFY_FETCHES = false
143array(8) {
144  ["id"]=>
145  int(1)
146  [0]=>
147  int(1)
148  ["float_col"]=>
149  float(2.6)
150  [1]=>
151  float(2.6)
152  ["double_col"]=>
153  float(3.6)
154  [2]=>
155  float(3.6)
156  ["decimal_col"]=>
157  string(4) "4.60"
158  [3]=>
159  string(4) "4.60"
160}
161
162done!
163