Skip to content

Commit dd983d9

Browse files
committed
Reproduce unexpected MySQL warnings for binary values
The prepared statement emulation layer is handling binary content in a way that creates warnings in MySQL. When analysing the query logs, we saw that the content sent to the server is missing `0x5C` characters when the using emulated prepares. This introduces a minimal test case that reproduces the issue to aid the solution. More info: doctrine/dbal#6522 (comment) Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
1 parent a87ccc7 commit dd983d9

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
MySQL PDO->prepare(), no warnings should be raised for binary values using emulated PS
3+
--EXTENSIONS--
4+
pdo_mysql
5+
--SKIPIF--
6+
<?php
7+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8+
MySQLPDOTest::skip();
9+
$db = MySQLPDOTest::factory();
10+
?>
11+
--FILE--
12+
<?php
13+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
14+
$db = MySQLPDOTest::factory();
15+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
16+
17+
$content = '0191D886E6DC73E7AF1FEE7F99EC6235';
18+
19+
$statement = $db->prepare('SELECT HEX(?) as test');
20+
$statement->bindValue(1, hex2bin($content), PDO::PARAM_LOB);
21+
$statement->execute();
22+
23+
var_dump($statement->fetchAll(PDO::FETCH_ASSOC)[0]['test'] === $content);
24+
var_dump($db->query('SHOW WARNINGS')->fetchAll(PDO::FETCH_ASSOC));
25+
26+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
27+
28+
$statement2 = $db->prepare('SELECT HEX(?) as test');
29+
$statement2->bindValue(1, hex2bin($content), PDO::PARAM_LOB);
30+
$statement2->execute();
31+
32+
var_dump($statement2->fetchAll(PDO::FETCH_ASSOC)[0]['test'] === $content);
33+
34+
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); // SHOW WARNINGS can only be used when PDO::ATTR_EMULATE_PREPARES=true
35+
var_dump($db->query('SHOW WARNINGS')->fetchAll(PDO::FETCH_ASSOC));
36+
print "done!";
37+
?>
38+
--EXPECTF--
39+
bool(true)
40+
array(0) {
41+
}
42+
bool(true)
43+
array(0) {
44+
}
45+
done!

0 commit comments

Comments
 (0)