我正在尝试将以下MYSQL
查询转换为PDO
具有准备和执行功能的语句,但由于我是新手,PDO
我不知道如何将其转换为PDO
语句!有任何想法吗?
$db = new PDO('mysql:dbname=MYDBNAME;host=MYHOST', 'USERNAME', 'PASSWORD');
$searchName = $db->quote($_GET["searchstr"]);
$searchTerms = explode(' ', $searchName);
$searchTermBits = array();
foreach ($searchTerms as $term)
{
$term = trim($term);
if (!empty($term))
$searchTermBits[] = "f_name LIKE '%$term%' OR l_name LIKE '%$term%'";
else
$searchTermBits[] = "f_name = '$term'";
}
$mysqlResult = $db->query("SELECT * FROM food_tbl WHERE (" . implode(' OR ', $searchTermBits) . ") AND country_id = 1 ORDER BY id DESC;");