dpnv33177 2018-03-04 13:48
浏览 36
已采纳

PDO插入BindParam mysql

Is it possible to use an array in the BindParam();? i mean like this:

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

OR Do you have to bind them 1 by 1 like:

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

1条回答 默认 最新

  • down2323 2018-03-04 13:50
    关注

    No, you cannot use an array with bindParam. In these cases, it is best to refer to the manual: http://php.net/manual/en/pdostatement.bindparam.php

    However, you can use an array with execute:

    $stmt = $this->Db->prepare("INSERT INTO test (name,age) VALUES (:name,:age)");
    $stmt->execute(array(":name"=>"michael",
                         ":age"=>"21"
                   ));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号