Skip to content

Commit

Permalink
add test phpgh-11587.phpt
Browse files Browse the repository at this point in the history
  • Loading branch information
SakiTakamachi committed Jul 7, 2023
1 parent 970fc9f commit 2f637d9
Showing 1 changed file with 149 additions and 0 deletions.
149 changes: 149 additions & 0 deletions ext/pdo_mysql/tests/gh-11587.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?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);

// 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--
<?php
require __DIR__ . '/mysql_pdo_test.inc';
MySQLPDOTest::dropTestTable();
?>
--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!

0 comments on commit 2f637d9

Please sign in to comment.