如何在Query绑定参数中放置2个以上的条件

时间:2016-03-01 09:02:06

标签: php mysql sql parameters phalcon

您正在处理参数绑定查询Phalcon。以下是我的代码

$conditions = "client = :client: AND inv_date = :inv_date: AND date_sent = :date_sent: AND date_received = :date_received:";
        $parameters = array(
            "client" => $search_client,
            "inv_date" => $invoice_date,
            "date_sent" => $date_sent,
            "date_received" => $date_received
        );
$invoices = Invoices::find(
    array(
        $conditions,
        "bind" => $parameters
    )
);

我是否正确使用AND? 仅供参考,如果我尝试以下操作,它可以正常工作:

$conditions = "client = :client: AND inv_date = :inv_date:";
$parameters = array(
    "client" => $search_client,
);
$invoices = Invoices::find(
    array(
        $conditions,
        "bind" => $parameters
    )
);

表格中存在所有字段,我认为还有其他方法可以使用多个AND

1 个答案:

答案 0 :(得分:1)

$conditions = "client = :client: AND inv_date = :inv_date:";
$parameters = array(
    "client" => $search_client,
);
$invoices = Invoices::find(
    array(
        $conditions,
        "bind" => $parameters
    )
);

此代码不起作用,因为您只传递一个参数客户端,但必须传递2个参数:client和inv_date。

$parameters = array(
    "client" => $search_client,
    "inv_date" => $invoice_date,
);

因此 - 您可以使用此选项(因为它确实有效),或者您可以像@Niki Mihaylov一样使用andWhere建议。