Skip to content

bindParamsFromArray to also accept associative arguments #41

@geertvanbommel

Description

@geertvanbommel

In PDO it's common to also provide an associative array of variables in the form of ":name", as well as question mark placeholders. (http://php.net/manual/en/pdostatement.bindparam.php)

So it would be awesome if $query->bindParamsFromArray($args); also supported this.

// Example:
$stmt = 'update table set foo=:bar, foo2=:bar2 where id=:id';

$args = array(':bar'=>'my value',':bar2'=>"my \"second\" value", ':id'=>123);
// or without semicolons:
$args = array('bar'=>'my value',  'bar2'=>"my \"second\" value", 'id'=>123);

// Desired result:
update table set foo='my value', foo2='my "second" value' where id=123

// Potential error in case of mismatching
// SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

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