Skip to content

pdo_firebird: It is not possible to pass a NULL value as an input parameter if the field is marked as NOT NULL. #15604

Closed
@sim1984

Description

@sim1984

Description

The following code:

<?php

$dbh = new PDO('firebird:dbname=inet://localhost/employee', 'SYSDBA', 'masterkey');

$dbh->exec('
recreate table t_bug_0001 (
  id bigint not null,
  a int not null,
  b int,
  constraint pk_bug_0001 primary key(id)
)
');

$dbh->exec('recreate sequence g_bug_0001');

$dbh->exec(<<<'SQL'
create or alter trigger t_bug_0001_bi0 for t_bug_0001
active before insert position 0
as
begin
  if (new.id is null) then
    new.id = next value for g_bug_0001;
end
SQL
);

$stmt = $dbh->prepare('insert into t_bug_0001(id, a, b) values(?, ?, ?)');
$stmt->execute([null, 1, 2]);
$stmt->execute([2, 2, null]);
unset($stmt);

$stmt2 = $dbh->prepare('SELECT id, a, b FROM t_bug_0001 WHERE id = ?');

$stmt2->execute([null]); 
$data = $stmt2->fetch(\PDO::FETCH_ASSOC);
$stmt2->closeCursor();
var_dump($data);

$stmt2->execute([2]); 
$data = $stmt2->fetch(\PDO::FETCH_ASSOC);
$stmt2->closeCursor();
var_dump($data);

unset($stmt2);

$dbh->exec('drop table t_bug_0001');
$dbh->exec('drop sequence g_bug_0001');

echo "\nOK\n";

Resulted in this output:

PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY105]: Invalid parameter type: -999 Parameter requires non-null value in D:\IBase\php-test\null_params.php:28
Stack trace:
#0 D:\IBase\php-test\null_params.php(28): PDOStatement->execute()
#1 {main}
  thrown in D:\IBase\php-test\null_params.php on line 28

But I expected this output instead:

bool(false)
array(3) {
  ["ID"]=>
  int(2)
  ["A"]=>
  int(2)
  ["B"]=>
  NULL
}

OK

PHP Version

PHP 8.3, PHP 8.4Beta3

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions