gpt4 book ai didi

php - 用 OR 条件绑定(bind)参数 Mysql

转载 作者:行者123 更新时间:2023-11-29 09:50:37 24 4
gpt4 key购买 nike

我正在使用绑定(bind)参数进行 MySQL 查询

    $variation_type = 'classification';
$currentSku = 1212;
$enrollBind = array('parent_sku' => $currentSku,'variation_type' => $variation_type);
$enrollQuery = "select variation_value
from product_map
where parent_sku =:parent_sku
and variation_type =:variation_type
and variation_value <>''
group by variation_value";

我的问题是我需要在查询中使用 OR 条件

$variation_type = 'classification'; 

$variation_type = 'test';

如何在绑定(bind)参数中使用此 OR 条件?

有人可以帮我解决这个问题吗?

最佳答案

您可以使用IN与多个值进行比较,例如:

$enrollQuery = "select variation_value 
from product_map
where parent_sku =:parent_sku and variation_type IN('classification', 'test')
and variation_value <>'' group by variation_value";

对于 php,您可以将其绑定(bind)在不同的变量中,并在查询中使用它,例如 variation_type IN(:classification_type, :test_type)

更新

您可以将两个值作为不同的参数传递,例如:

$classification_variation_type = 'classification';
$test_variation_type = 'test';
$enrollBind = array('parent_sku' => $currentSku,'classification_variation_type' => $classification_variation_type, 'test_variation_type' => $test_variation_type);
$enrollQuery = "select variation_value
from product_map
where parent_sku =:parent_sku
and variation_type = IN(:classification_variation_type, :test_variation_type)
and variation_value <>''
group by variation_value";

关于php - 用 OR 条件绑定(bind)参数 Mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54883055/

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