我有一个包含大约 100.000 名客户的数据库可供搜索,使用我的搜索表单更好的做法和最快的做法是:
这样做会更好吗
if(strlen($_POST['firstname']))
{
$search .= "AND `firstname` like :firstname";
}
if(strlen($_POST['lastname']))
{
$search .= "AND `lastname` like :lastname";
}
// and so on for about 16 possible fields
或者做
$query = $this->db->query("SELECT * FROM `customers`
WHERE `firstname` LIKE :firstname,
AND `lastname` LIKE :lastname,
-- AND so on for about 16 elements");