Prefixing array keys with a string (:) in PHP

后端 未结 4 611
臣服心动
臣服心动 2021-01-18 10:56

Quick one; I know a solution, but I\'m looking for something more elegant if it exists.

I\'m using PDO for prepeared statements:

$sql = \"INSERT INTO         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-18 11:27

    $source->execute($sql, array(
        'foo' => $foo,
        'bar' => $bar,
        'baz' => $baz
    ));
    

    This is presuming the above calls PDOStatement::execute() under the hood, with the above array as its argument.1

    :)


    1) Tested with version 5.2.17 and 5.3.8 here, and working as expected.

提交回复
热议问题