Skip to content

Commit 93c68ca

Browse files
lcobuccimbeccati
authored andcommitted
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 5c7c5d9 commit 93c68ca

File tree

1 file changed

+44
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)