Skip to content

[BUG]: DataMapper columns() binds no value for a null value #17817

Todo

Description

@niden

Describe the bug
Phalcon\DataMapper\Query\Insert::columns() and Update::columns() call column() for each pair. column() with a null value adds the token :name and binds no value, because a column() with no value means "bind it later". So columns(['score' => null]) gives a token with no value, where the caller gives the value null.

To Reproduce

$insert = $factory->newInsert($connection);
$insert
    ->into('scores')
    ->columns(['name' => 'Ann', 'score' => null])
    ->perform();

On MySQL: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. SQLite accepts it, and gives NULL to a token with no value.

Expected behavior
In the map form of columns() (a string key), a null value is a value: the token is bound to null. The list form (an integer key, only the column name) keeps "bind it later". column($name) with no value keeps "bind it later" too.

This changes what columns() does with null, so it is for 7.0.

Details

  • Phalcon version: 5.0.x (927c773be7): phalcon/DataMapper/Query/Insert.zep and Update.zep, column() (line 46; the check if null !== value on line 50) and columns() (line 62).
  • phalcon/phalcon v6.0.x (aeca48611) has the same code: src/DataMapper/Query/Insert.php (column(), line 57) and src/DataMapper/Query/Update.php (column(), line 55).

Additional context
Found in phalcon/crest#84 (make:repository). The repository base of crest calls set($column) (it writes NULL) for a null value, and column() for the other values. Crest keeps that code; this issue is for the next major version.

Activity

  1. self-assigned this
    on Nov 27, 2026
  2. added theissue type on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

7.0bugstatus: low

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions