本文介绍了php sql 多bind_param的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经做到了这一点.

so far I've come to this.

我的目标是能够在需要时应用可选的搜索过滤器,例如 a.chainid 和 a.branchid,为此我需要动态 bind_param.

My goal is to be able to apply optional search filters such as a.chainid and a.branchid if needed, for that to happen I need dynamic bind_param.

代码看起来不错,但实际上由于某种原因不起作用.

The code seems to be fine, but in fact it's not working for some reason.

介意告诉我有什么问题吗?

Care to tell me what's wrong?

fetch 没有返回任何东西,而是应该返回 5 行.

The fetch returns me nothing instead of 5 rows that should.

提前致谢

$sql = "SELECT a.COUPONID, a.TRUSTANDUSEID FROM `custom_redemptions` a WHERE a.couponid = 3";

    $types = '';
    $params = array(&$types);

    if ($branchid != null) {
        $sql .= "AND a.branchid = ?";
        $types .= 's';
        $params[] = $branchid;
    }
    if ($chainid != null) {
        $sql .= "AND a.chainid = ?";
        $types .= 's';
        $params[] = $chainid;
    }

    if ($stmt = $this->dbCon->prepare($sql)) {
        call_user_func_array(array($stmt, 'bind_param'), $params);
        $stmt->execute();
        $stmt->bind_result($couponid, $trustanduseid);
        while ($stmt->fetch()) { echo $couponid; }
        $stmt->close();
    }

推荐答案

最后需要的是 &$chainid 而不是 $chainid.

Finally what was needed was &$chainid instead of $chainid.

花了 8 个小时研究它.哈哈

Spent 8 hours researching about it. LOL

这篇关于php sql 多bind_param的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 00:03