Skip to content

Instantly share code, notes, and snippets.

@cebe
Last active August 14, 2017 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cebe/badfec47a8c3fcc4ffcf1625ca8e0655 to your computer and use it in GitHub Desktop.
Save cebe/badfec47a8c3fcc4ffcf1625ca8e0655 to your computer and use it in GitHub Desktop.
Reproducing a PHP PDO bug
<?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";
}
$ 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
$ 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
@cebe
Copy link
Author

cebe commented Aug 14, 2017

Seems this is fixed in PHP 7.1.7:

$ /opt/php/php-dist/php-7.1.7-custom/bin/php --version
PHP 7.1.7 (cli) (built: Jul 31 2017 14:42:03) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
$ /opt/php/php-dist/php-7.1.7-custom/bin/php bug.php 
1
2
3
---
1
2
3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment