php mysql准备的语句LIKE在Wordpress中不起作用

时间:2019-01-17 02:27:00

标签: php mysql wordpress

我知道这个SO post。但是,我准备的声明仍然无法正常工作。

这里是名为$parameterized的数组:

array(4) {
  [0]=>
  string(11) "1234567"
  [1]=>
  string(11) "1234567"
  [2]=>
  string(17) "%36.5 (u.s. 6.5)%"
  [3]=>
  string(13) "%37 (u.s. 7)%"
}

这是我准备好的名为$query的查询:

   SELECT DISTINCT products.*, prices.max_price, prices.min_price, prices.compare_at_price, collects.position 
    FROM products 
    INNER JOIN collects 
    ON products.product_id = collects.product_id 
    AND collects.collection_id = %d  
    INNER JOIN (
      SELECT variants.product_id, MAX(variants.price) AS max_price, MIN(variants.price) AS min_price, MAX(variants.compare_at_price) AS compare_at_price 
      FROM variants 
      INNER JOIN collects 
      ON variants.product_id = collects.product_id 
      WHERE collects.collection_id = %d AND (variants.option1 LIKE ? OR variants.option1 LIKE ?) 
      GROUP BY product_id ORDER BY NULL
      ) prices ON products.product_id = prices.product_id 
    ORDER BY collects.position ASC LIMIT 0,12

这是我执行$productsQuery = $wpdb->prepare($query, $parameterized)时该预准备查询的预准备语句:

SELECT DISTINCT products.*, prices.max_price, prices.min_price, prices.compare_at_price, collects.position 
FROM products 
INNER JOIN collects 
ON products.product_id = collects.product_id 
AND collects.collection_id = 1234567  
INNER JOIN (
  SELECT variants.product_id, MAX(variants.price) AS max_price, MIN(variants.price) AS min_price, MAX(variants.compare_at_price) AS compare_at_price 
  FROM variants 
  INNER JOIN collects 
  ON variants.product_id = collects.product_id 
  WHERE collects.collection_id = 1234567 AND (variants.option1 LIKE ? OR variants.option1 LIKE ?) 
  GROUP BY product_id ORDER BY NULL
  ) prices ON products.product_id = prices.product_id 
ORDER BY collects.position ASC LIMIT 0,12

请注意WHERE collects.collection_id = 97476673649 AND (variants.option1 LIKE ? OR variants.option1 LIKE ?),其中?是问号,以及如何不将它们替换为"%36.5 (u.s. 6.5)%""%37 (u.s. 7)%"

我的$parameterized数组有问题吗?我在该数组中的LIKE参数不正确吗?还是我的SQL字符串中的符号?-variants.option1 LIKE ? OR variants.option1 LIKE ?-无效?

0 个答案:

没有答案