du12197 2015-09-29 22:10
浏览 75

PDO foreach循环遍历bindParam与引用返回错误的结果

I think I've read many topics on that question but still get a wrong result. I have a query parameters array that I want to loop with foreach() to bind parameters.

foreach($aQueryParams as $key => &$value){
    $stmt->bindParam($key, $value);
}

This concerns an INSERT query and what I get as a result is the key inserted in my table instead of the value. But I'm sure that the key and the value are good and at the good place. A var_dump() on $key and $value give :firstName for the $key and Samy for the &$value. But this is :firstName that is inserted in my table...

And I also tried with a bindValue without using the reference and it's the same result.

To be clearer, I give you the link of the gitHub repository. You can see the declaration of the parameters array in ClientManager.class.php at line 44, and the foreach() loop to bind parameters in DBOperation.class.php at line 97. https://github.com/code-climber/car_rental/blob/preparedStmt/src/car_rental/model/dao/ClientManager.class.php

I'm going mad with this.

  • 写回答

1条回答 默认 最新

  • doushan2811 2015-09-30 12:45
    关注

    Ok, I finally found what was wrong. This was my SQL query. I had put some quotes around each VALUES parameters. As I did not have error message, I focused only on the thing which was new to me, the loop over the bindParam().

    I find the moderator a bit severe about the clarity of my question because I really read all I can on the reference...It was not a duplicate. The error was elsewhere.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向