Php函数,错误:变量数量与准备语句中的参数数量不匹配

时间:2017-03-24 15:18:28

标签: php mysql

我正面临一个错误:mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement即使我计算了所有参数并且相等。

我调用选择查询的功能:

   public function User_depodit ($Phone_number) {
  $stmt = $this->conn->prepare("SELECT a.Idcustomer_info as             idInfocustomer, a.Amount as currentamountCustInfo, b.Idcustomer_info as    idInfocustomer2, b.IDcustomer , c.IDbank AS DepositIDbank, c.Amount as currentAmountDpsit, c.IDcustomer as IDcustomerDepodit,bnk.IDbank as bankIDbank, d.Card_Id as CardID_cardType ,         d.CardName , e.Amount as VisaAmount, e.Card_number as visaCardNumber, e.Exp_date      as VisaExpDate,e.Security_code as visaSecurityCod, e.Card_Id AS visaCardId from     customer_info a join customer b on a.Idcustomer_info = b.Idcustomer_info join     deposit c on b.IDcustomer =c.IDcustomer join bank bnk on c.IDbank = bnk.IDbank       join cardtype d on bnk.Card_Id= d.Card_Id join visa_info e on d.Card_Id = e.Card_Id where a.Phone_number ='?' ORDER BY a.Created_at DESC ,c.Created_at DESC ,e.Created_at DESC limit 1");
 $stmt->bind_param("iiiiiiiiiiiiiii", $idInfocustomer,    $currentamountCustInfo, $idInfocustomer2, $IDcustomer, $DepositIDbank,    $currentAmountDpsit, $IDcustomerDepodit, $bankIDbank, $CardID_cardType,   $CardName, $VisaAmount, $visaCardNumber, $VisaExpDate, $visaSecurityCod,   $visaCardId);
    if ($stmt->execute()) {
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();

            // return user's results
            return $user;     
        }
        else {
        return NULL;
    }
}

1 个答案:

答案 0 :(得分:0)

我错误地绑定了错误的参数,我最终将其修复如下:

 public function UserDepodit ($Phone_number) {

 $stmt = $this->conn->prepare("SELECT
                         a.Idcustomer_info as idInfocustomer,
                         a.Amount as currentamountCustInfo, 
                         b.Idcustomer_info as idInfocustomer2, 
                         b.IDcustomer , 
                         c.IDbank AS DepositIDbank, 
                         c.Amount as currentAmountDpsit, 
                         c.IDcustomer as IDcustomerDepodit,
                         bnk.IDbank as bankIDbank, 
                         d.Card_Id as CardID_cardType , 
                         d.CardName , 
                         e.Amount as VisaAmount, 
                         e.Card_number as visaCardNumber, 
                         e.Exp_date as VisaExpDate,
                         e.Security_code as visaSecurityCod, 
                         e.Card_Id AS visaCardId

                         from customer_info a 
                         join customer b 
                         on a.Idcustomer_info = b.Idcustomer_info 
                         join deposit c 
                         on b.IDcustomer = c.IDcustomer 
                         join bank bnk 
                         on c.IDbank = bnk.IDbank 
                         join cardtype d 
                         on bnk.Card_Id= d.Card_Id 
                         join visa_info e 
                         on d.Card_Id = e.Card_Id

                         where a.Phone_number = ? 
                         ORDER BY a.Created_at DESC ,
                         c.Created_at DESC ,
                         e.Created_at DESC limit 1");


  $stmt->bind_param("i", $Phone_number);


    if ($stmt->execute()) {
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();

            // return user's results
            return $user;


        }
        else {
        return NULL;
    }
}