dougan5772 2016-06-25 00:46
浏览 111
已采纳

PHP:如何将数组传递给bind_param

I've been trying to figure this out.

$insertSql = 'INSERT INTO table (id,date,name,numFarts) VALUES (?,?,?,?)';
$values = (1,'0000-00-00 00:00:00','Bob',5);
$bind_param_str = ('issi');
if ($stmt = $db->prepare ($insertSql)) { // $inserSql is a pre-writted sql insert
     $stmt->bind_param($bind_param_str,$values);
     $stmt->execute();
     $stmt->close();
}

This doesn't work, but I can't think of any other way to pass $values into bind_param()

Any ideas?

  • 写回答

1条回答 默认 最新

  • douhang5460 2016-06-25 04:27
    关注

    For any function that you need to pass an array as the argument/s you can use call_user_func_array.

    In this example:

    array_unshift($values,$bind_param_str);
    call_user_func_array(array($stmt,'bind_param'),$values);
    

    Don't ask me why you need array($stmt,'bind_param') instead of $stmt->bind_param. Has something to do with the syntax of -> I'm sure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭