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 VB.NET 父窗体调取子窗体报错
    • ¥15 python海龟作图如何改代码使其最后画出来的是一个镜像翻转的图形
    • ¥15 我不明白为什么c#微软的官方api浏览器为什么不支持函数说明的检索,有支持检索函数说明的工具吗?
    • ¥15 ORBSLAM2框架跑ICL-NUIM数据集
    • ¥15 在我想检测ros是否成功安装时输入roscore出现以下
    • ¥30 老板让我做一个公司的投屏,实时显示日期,时间,安全生产的持续天数,完全没头绪啊
    • ¥15 Google Chrome 所有页面崩溃,三种解决方案都没有解决,我崩溃了
    • ¥20 使用uni-app发起网络请求,获取重定向302返回的cookie
    • ¥20 手机外部浏览器拉起微信小程序支付 (相关搜索:微信小程序)
    • ¥20 怎样通过一个网址找到其他同样模版的网址