在php mysqli中结合普通查询和准备好的查询

时间:2014-03-17 09:04:25

标签: php mysqli

我使用了以下php mysqli数据库类 PHP MYSqli class

在下面的案例中,我如何使用预备陈述

$qry =  " SELECT * FROM Master WHERE CustomerID = $customer_id ";
    $qry.= (!empty($type)) ? " and Type=? " : "";
    $qry.= (!empty($status)) ? " and Status=$status " : "";
    $qry.= (!empty($inline)) ? " and $inline " : "";
    $qry.= " ORDER BY JobID DESC ";
    $start =  !(empty($limit)) ? ($list_limit[$limit] * $page) : 0;
    $end =  !(empty($limit)) ? $list_limit[$limit]   : 20;
    $qry.= " LIMIT $start,$end ";
    //echo $qry;
    return $results = $db->rawQuery($qry,array($type));

执行上述操作时,错误为

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in /var/www/proj/lib/mydb.php on line 64

1 个答案:

答案 0 :(得分:1)

您的问题是变量的数量与预准备语句中的参数数量不匹配。他们必须匹配。

另请注意,您不应该结合正常的"并准备好查询。您的所有查询都必须准备好。