|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-09 02:02 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
Description: ------------ Null handling in atleast PDO sqlite driver seems broken. Seems impossible to use prepared statements with NULL values. They appear to get converted to an empty string. Reproduce code: --------------- <?php $pdo = new PDO('sqlite::memory:'); $pdo->exec('CREATE TABLE test(ID INT NOT NULL PRIMARY KEY, Field VARCHAR(12) NULL);'); $stmt = $pdo->prepare('INSERT INTO test(ID, Field) VALUES(?, ?)'); $one = 1; $two = 2; $null = NULL; // Try with PDO_PARAM_NULL $stmt->bindParam(1, $one, PDO_PARAM_INT); $stmt->bindParam(2, $null, PDO_PARAM_NULL); assert($stmt->execute()); // Try with PDO_PARAM_STR $stmt->bindParam(1, $two, PDO_PARAM_INT); $stmt->bindParam(2, $null, PDO_PARAM_STR); assert($stmt->execute()); // Check we have rows.. $stmt = $pdo->prepare('SELECT * FROM test'); assert($stmt->execute()); var_dump($stmt->fetchAll(PDO_FETCH_OBJ)); // Check we have rows with field is null echo '<hr />'; $stmt = $pdo->prepare('SELECT * FROM test WHERE Field IS NULL'); assert($stmt->execute()); var_dump($stmt->fetchAll(PDO_FETCH_OBJ)); ?> Expected result: ---------------- 2 rows in table test where Field column is null. Actual result: -------------- 2 Rows in table test with Field is an empty string.