我正在对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 Param中使用此OR条件?
有人可以帮我吗?
答案 0 :(得分:1)
您可以使用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,您可以将其绑定到不同的变量中,并在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";