gpt4 book ai didi

php - 如何在查询绑定(bind)参数中放置两个以上的条件

转载 作者:行者123 更新时间:2023-11-28 23:36:01 27 4
gpt4 key购买 nike

您好,我正在处理参数绑定(bind)查询 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

最佳答案

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

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

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

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

关于php - 如何在查询绑定(bind)参数中放置两个以上的条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35718501/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com