I have a query like this in Drupal 6:
$sql = 'SELECT sid, score FROM search_index WHERE word LIKE "%%%s%%"';
$result = db_query($sql,$search_term);
And it worked fine, but now I'm upgrading to Drupal 7.
I read up and this is supposed to work, but it's not:
$sql = 'SELECT sid, score FROM search_index WHERE word LIKE "%:term"';
$result = db_query($sql,array(':term'=>$search_term));
D7 中 正确答案:
$sql = 'SELECT sid, score FROM {search_index} WHERE word LIKE :term';
$result = db_query($sql, array(':term' => '%' . db_like($search_term)));