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

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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?