为了使用PDO进行LIKE搜索,我需要在传递参数之前将%
添加到参数中。如何使用PDO进行LIKE搜索?
这工作:
$qry = '
SELECT product_id
FROM cart_product
WHERE product_manufacturer_num LIKE :search_string
';
$sth = $this->pdo->prepare($qry);
$sth->execute(array("search_string"=>'%'.$search_string.'%'));
对我来说,这种感觉更像是一个黑客,是否有这样做的一个更正式的方式?
重复的:http://stackoverflow.com/questions/583336/how-do-i-create-a-pdo-parameterized-query-with-a-like-statement-in-php/7357296#7357296 – Kzqai 2011-09-09 04:56:34