Last active
February 5, 2016 07:07
-
-
Save chuyskywalker/21e08988fe90c8d95eec to your computer and use it in GitHub Desktop.
memsql doesn't like medium ints on prepared statements
This file contains 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 | |
echo '<pre>'; | |
/* | |
Have a table like | |
CREATE TABLE `inty` ( | |
`biu` bigint unsigned NOT NULL AUTO_INCREMENT, | |
`bis` bigint NOT NULL , | |
`iu` int UNSIGNED NOT NULL , | |
`is` int NOT NULL , | |
`miu` mediumint UNSIGNED NOT NULL , | |
`mis` mediumint NOT NULL , | |
`tiu` tinyint UNSIGNED NOT NULL , | |
`tis` tinyint NOT NULL , | |
PRIMARY KEY (`biu`) | |
) | |
insert into `inty` VALUES | |
(1, 1, 1, 1, 1, 1, 1, 1), | |
(2, -1, 1, -1, 1, -1, 1, -1), | |
(3, 0, 0, 0, 0, 0, 0, 0) | |
; | |
> select * from inty; | |
+-----+-----+----+----+-----+-----+-----+-----+ | |
| biu | bis | iu | is | miu | mis | tiu | tis | | |
+-----+-----+----+----+-----+-----+-----+-----+ | |
| 2 | -1 | 1 | -1 | 1 | -1 | 1 | -1 | | |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | | |
| 3 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | | |
+-----+-----+----+----+-----+-----+-----+-----+ | |
3 rows in set (0.00 sec) | |
*/ | |
// fill in as needed | |
$pdo = new PDO("mysql:host=192.168.1.60;port=3306;dbname=forums", 'root', ''); | |
$q = 'SELECT * FROM inty WHERE biu = ?'; | |
$v = [1,2,3]; | |
foreach ($v as $id) { | |
$retVals = []; | |
foreach (['unprepared', 'prepared'] as $style) { | |
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, $style == 'unprepared'); | |
$stmt = $pdo->prepare($q); | |
$stmt->execute([$id]); | |
$retVals[$style] = $stmt->fetch(PDO::FETCH_ASSOC); | |
$stmt->closeCursor(); | |
} | |
echo "$id: " . print_r($retVals, 1); | |
} |
This file contains 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
1: Array | |
( | |
[unprepared] => Array | |
( | |
[biu] => 1 | |
[bis] => 1 | |
[iu] => 1 | |
[is] => 1 | |
[miu] => 1 | |
[mis] => 1 | |
[tiu] => 1 | |
[tis] => 1 | |
) | |
[prepared] => Array | |
( | |
[biu] => 1 | |
[bis] => 1 | |
[iu] => 1 | |
[is] => 1 | |
[miu] => 16777217 | |
[mis] => 16842752 | |
[tiu] => 0 | |
[tis] => -2 | |
) | |
) | |
2: Array | |
( | |
[unprepared] => Array | |
( | |
[biu] => 2 | |
[bis] => -1 | |
[iu] => 1 | |
[is] => -1 | |
[miu] => 1 | |
[mis] => -1 | |
[tiu] => 1 | |
[tis] => -1 | |
) | |
[prepared] => Array | |
( | |
[biu] => 2 | |
[bis] => -1 | |
[iu] => 1 | |
[is] => -1 | |
[miu] => 4278190081 | |
[mis] => -16646145 | |
[tiu] => 0 | |
[tis] => -2 | |
) | |
) | |
3: Array | |
( | |
[unprepared] => Array | |
( | |
[biu] => 3 | |
[bis] => 0 | |
[iu] => 0 | |
[is] => 0 | |
[miu] => 0 | |
[mis] => 0 | |
[tiu] => 0 | |
[tis] => 0 | |
) | |
[prepared] => Array | |
( | |
[biu] => 3 | |
[bis] => 0 | |
[iu] => 0 | |
[is] => 0 | |
[miu] => 0 | |
[mis] => 0 | |
[tiu] => 0 | |
[tis] => -2 | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rev 4 makes a more complete test and shows that both
mediumint
andtinyint
both have problems when going through the proper escaping.