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 Qt 不小心删除了自带的类,该怎么办
    • ¥15 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!