mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
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: https://github.com/doctrine/dbal/pull/6522#issuecomment-2340939347 Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
This commit is contained in:
parent
5c7c5d93ae
commit
93c68caeb5
1 changed files with 44 additions and 0 deletions
44
ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_binary.phpt
Normal file
44
ext/pdo_mysql/tests/pdo_mysql_prepare_emulated_binary.phpt
Normal file
|
@ -0,0 +1,44 @@
|
|||
--TEST--
|
||||
MySQL PDO->prepare(), no warnings should be raised for binary values using emulated PS
|
||||
--EXTENSIONS--
|
||||
pdo_mysql
|
||||
--SKIPIF--
|
||||
<?php
|
||||
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
|
||||
MySQLPDOTest::skip();
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/inc/mysql_pdo_test.inc';
|
||||
$db = MySQLPDOTest::factory();
|
||||
$db->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!
|
Loading…
Add table
Add a link
Reference in a new issue