PDO插入BindParam mysql

时间:2018-03-04 13:48:29

标签: php mysql pdo

是否可以在BindParam()中使用数组;? 我的意思是这样的:

$stmt = $this->Db->prepare("INSERT INTO test (name,age) VALUES (:name,:age)");
$stmt->BindParam(array(":name"=>"michael",
                       ":age"=>"21"
                 ));
$stmt->execute();

OR 你必须像1一样将它们绑定:

$stmt->BindParam(":name","Michael");
$stmt->BindParam(":age","21");
$stmt->execute();

1 个答案:

答案 0 :(得分:0)

不,您不能将数组与bindParam一起使用。在这些情况下,最好参考手册:http://php.net/manual/en/pdostatement.bindparam.php

但是,您可以使用带有execute的数组:

$stmt = $this->Db->prepare("INSERT INTO test (name,age) VALUES (:name,:age)");
$stmt->execute(array(":name"=>"michael",
                     ":age"=>"21"
               ));
相关问题