From 93c68caeb552018c5c9efe0a6e7bf99ac47b169f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Wed, 18 Sep 2024 20:14:33 +0200 Subject: [PATCH] Reproduce unexpected MySQL warnings for binary values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/doctrine/dbal/pull/6522#issuecomment-2340939347 Signed-off-by: Luís Cobucci --- .../pdo_mysql_prepare_emulated_binary.phpt | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_binary.phpt diff --git a/ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_binary.phpt b/ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_binary.phpt new file mode 100644 index 00000000000..fe198376d61 --- /dev/null +++ b/ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_binary.phpt @@ -0,0 +1,44 @@ +--TEST-- +MySQL PDO->prepare(), no warnings should be raised for binary values using emulated PS +--EXTENSIONS-- +pdo_mysql +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_EMULATE_PREPARES, true); + + $content = '0191D886E6DC73E7AF1FEE7F99EC6235'; + + $statement = $db->prepare('SELECT HEX(?) as test'); + $statement->bindValue(1, hex2bin($content), PDO::PARAM_LOB); + $statement->execute(); + + var_dump($statement->fetchAll(PDO::FETCH_ASSOC)[0]['test'] === $content); + var_dump($db->query('SHOW WARNINGS')->fetchAll(PDO::FETCH_ASSOC)); + + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); + + $statement2 = $db->prepare('SELECT HEX(?) as test'); + $statement2->bindValue(1, hex2bin($content), PDO::PARAM_LOB); + $statement2->execute(); + + var_dump($statement2->fetchAll(PDO::FETCH_ASSOC)[0]['test'] === $content); + + $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); // SHOW WARNINGS can only be used when PDO::ATTR_EMULATE_PREPARES=true + var_dump($db->query('SHOW WARNINGS')->fetchAll(PDO::FETCH_ASSOC)); + print "done!"; +?> +--EXPECTF-- +bool(true) +array(0) { +} +bool(true) +array(0) { +} +done!