mirror of
https://github.com/php/php-src.git
synced 2026-04-16 20:41:18 +02:00
The prepared statement emulator (pdo_sql_parser.*) figures out how to quote each query parameter. The intended type is specified by the PDO::PARAM_* consts, but this direction wasn't always followed. In practice, queries could work as expected, but subtle errors could result. For example, a numeric string bound as PDO::PARAM_INT would be sent to a driver's quote function. While these functions are told which type is expected, they generally assume values are being quoted as strings. This can result in implicit casts, which are bad for performance. This commit includes the following changes: - Cast values marked as bool/int/null to the appropriate type and bypass the driver's quote function. - Save some memory by dropping the temporary zval used for casting. - Avoid a memory leak if the driver's quote function produces an error. - Appropriate test suite updates.
44 lines
985 B
PHP
44 lines
985 B
PHP
--TEST--
|
|
PDO Common: Bug #73234 (Emulated statements let value dictate parameter type)
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded('pdo')) die('skip');
|
|
$dir = getenv('REDIR_TEST_DIR');
|
|
if (false == $dir) die('skip no driver');
|
|
require_once $dir . 'pdo_test.inc';
|
|
PDOTest::skip();
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
|
|
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
|
|
|
|
$db = PDOTest::factory();
|
|
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
|
$db->exec('CREATE TABLE test(id INT NULL)');
|
|
|
|
$stmt = $db->prepare('INSERT INTO test VALUES(:value)');
|
|
|
|
$stmt->bindValue(':value', 0, PDO::PARAM_NULL);
|
|
$stmt->execute();
|
|
|
|
$stmt->bindValue(':value', null, PDO::PARAM_NULL);
|
|
$stmt->execute();
|
|
|
|
$stmt = $db->query('SELECT * FROM test');
|
|
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
?>
|
|
--EXPECT--
|
|
array(2) {
|
|
[0]=>
|
|
array(1) {
|
|
["id"]=>
|
|
NULL
|
|
}
|
|
[1]=>
|
|
array(1) {
|
|
["id"]=>
|
|
NULL
|
|
}
|
|
}
|