Last active
August 14, 2017 10:30
-
-
Save cebe/badfec47a8c3fcc4ffcf1625ca8e0655 to your computer and use it in GitHub Desktop.
Reproducing a PHP PDO bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tableSql = <<<SQL | |
DROP TABLE IF EXISTS `typebug`; | |
CREATE TABLE `typebug` ( | |
`int_col` integer NOT NULL, | |
`int_col2` integer DEFAULT '1', | |
`smallint_col` smallint(1) DEFAULT '1', | |
`char_col` char(100) NOT NULL, | |
`char_col2` varchar(100) DEFAULT 'something', | |
`char_col3` text, | |
`enum_col` enum('a', 'B', 'c,D'), | |
`float_col` double(4,3) NOT NULL, | |
`float_col2` double DEFAULT '1.23', | |
`blob_col` blob, | |
`numeric_col` decimal(5,2) DEFAULT '33.22', | |
`time` timestamp NOT NULL DEFAULT '2002-01-01 00:00:00', | |
`bool_col` tinyint(1) NOT NULL, | |
`bool_col2` tinyint(1) DEFAULT '1', | |
`ts_default` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
`bit_col` BIT(8) NOT NULL DEFAULT b'10000010' | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
INSERT INTO `typebug` (`int_col`, `char_col`, `float_col`, `bool_col`) VALUES (1, 'A', 9.735, 1), (2, 'B', -2.123, 0), (3, 'C', 2.123, 0); | |
SQL; | |
$pdo = new PDO('mysql:host=127.0.0.1;dbname=yiitest', 'root', 'wurstepelle'); | |
$pdo->prepare($tableSql)->execute(); | |
$statement = $pdo->prepare("SELECT int_col FROM `typebug` WHERE `int_col` IN (1,2,3) ORDER BY `int_col`;"); | |
$statement->execute(); | |
$result = $statement->fetchAll(PDO::FETCH_ASSOC); | |
//print_r($result); | |
foreach($result as $row) { | |
echo $row['int_col'] . "\n"; | |
} | |
echo "---\n"; | |
$statement = $pdo->prepare("SELECT * FROM `typebug` WHERE `int_col` IN (1,2,3) ORDER BY `int_col`;"); | |
$statement->execute(); | |
$result = $statement->fetchAll(PDO::FETCH_ASSOC); | |
//print_r($result); | |
foreach($result as $row) { | |
echo $row['int_col'] . "\n"; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php5 --version | |
PHP 5.6.30-0+deb8u1 (cli) (built: Feb 8 2017 08:50:21) | |
Copyright (c) 1997-2016 The PHP Group | |
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies | |
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies | |
$ php5 pdobug.php | |
1 | |
2 | |
3 | |
--- | |
1 | |
2 | |
3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat /etc/debian_version | |
8.9 | |
$ mysql --version | |
mysql Ver 14.14 Distrib 5.5.57, for debian-linux-gnu (x86_64) using readline 6.3 | |
$ php71 --version | |
PHP 7.1.0alpha2 (cli) (built: Jul 4 2016 11:40:37) ( NTS ) | |
Copyright (c) 1997-2016 The PHP Group | |
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies | |
$ php7 --version | |
PHP 7.0.8 (cli) (built: Jul 4 2016 10:57:40) ( NTS ) | |
Copyright (c) 1997-2016 The PHP Group | |
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies | |
$ php71 pdobug.php | |
1 | |
2 | |
3 | |
--- | |
1 | |
3 | |
$ php7 pdobug.php | |
1 | |
2 | |
3 | |
--- | |
1 | |
3 | |
expected output: | |
1 | |
2 | |
3 | |
--- | |
1 | |
2 | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems this is fixed in PHP 7.1.7: