Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7ecea94

Browse files
lcobuccimbeccati
authored andcommittedSep 21, 2024
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 <[email protected]>
1 parent 64d959e commit 7ecea94

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)
Please sign in to comment.