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