php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62024 Cannot insert second row with null using parametrized query (Firebird PDO)
Submitted: 2012-05-14 13:35 UTC Modified: -
Votes:25
Avg. Score:4.9 ± 0.3
Reproduced:23 of 24 (95.8%)
Same Version:8 (34.8%)
Same OS:11 (47.8%)
From: matheus at gigatron dot com dot br Assigned:
Status: Closed Package: PDO related
PHP Version: 5.4.3 OS: Windows 7
Private report: No CVE-ID: None
 [2012-05-14 13:35 UTC] matheus at gigatron dot com dot br
Description:
------------
Using the firebird PDO driver and a parametrized insert query, you cannot use a null value for a column after issuing a query with a filled value for that same column.

On the snipped below, it should be possible to insert both rows, but the second one fails with an exception. If you invert the order of the inserts (insert $args_err before $args_ok) then the script runs.

Test script:
---------------
/**Reference table:
CREATE TABLE TEST_INSERT (
    ID    INTEGER NOT NULL,
    COL1  VARCHAR(40)
);
*/

$sql = "insert into test_insert (id, col1) values (?, ?);"

$args_ok = [1, "test1"];
$args_err = [2, null];

$res = $stmt->execute($args_ok);
var_dump($res);

$res = $stmt->execute($args_err);
var_dump($res);


Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
bool(true)
PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[HY105
]: Invalid parameter type: -999 Parameter requires non-null value' in F:\demos\p
hp\erro_insert_prep_null\test.php:42
Stack trace:
#0 F:\demos\php\erro_insert_prep_null\test.php(42): PDOStatement->execute(Array)

#1 {main}
  thrown in F:\demos\php\erro_insert_prep_null\test.php on line 42

Patches

Bind_Remember_Null (last revision 2012-10-25 08:33 UTC by james at kenjim dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-27 10:59 UTC] mr dot efrem at gmail dot com
This problem is observed still in php5-5.3.13.
 [2013-03-21 19:05 UTC] matheus at gigatron dot com dot br
I can confirm James' patch indeed seems to solve the problem (at least for this reproducible test script).

Would be nice if a developer could include this on the master php branch.
 [2013-05-31 14:33 UTC] mbeccati@php.net
Automatic comment on behalf of matheus@gigatron.com.br
Revision: http://git.php.net/?p=php-src.git;a=commit;h=df6ca450ce1bebb7a36c0d2eecb51a28ac2f5118
Log: Fixed bug #62024 (unable to run consecutive prepared querys with null values)
 [2013-05-31 14:33 UTC] mbeccati@php.net
-Status: Open +Status: Closed
 [2014-10-07 23:19 UTC] stas@php.net
Automatic comment on behalf of matheus@gigatron.com.br
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=df6ca450ce1bebb7a36c0d2eecb51a28ac2f5118
Log: Fixed bug #62024 (unable to run consecutive prepared querys with null values)
 [2014-10-07 23:30 UTC] stas@php.net
Automatic comment on behalf of matheus@gigatron.com.br
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=df6ca450ce1bebb7a36c0d2eecb51a28ac2f5118
Log: Fixed bug #62024 (unable to run consecutive prepared querys with null values)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 18:01:29 2024 UTC