Skip to content

Instantly share code, notes, and snippets.

@nocturnalact
Created January 21, 2014 23:09
Show Gist options
  • Select an option

  • Save nocturnalact/8550394 to your computer and use it in GitHub Desktop.

Select an option

Save nocturnalact/8550394 to your computer and use it in GitHub Desktop.
Search
public static function search($toid, $query)
{
$db = parent::getDB();
$sql = "SELECT *
FROM my_messages
WHERE message_date LIKE '%$query%' OR
message_subject LIKE '%$query%' OR
message_content LIKE '%$query%' )
ORDER BY message_date DESC
LIMIT 10";
if ($stmt = $db->prepare($sql)) {
// $query = '%' . strip_tags($query) . '%';
// $query = '%' . trim($query) . '%';
$stmt->bindParam(1, $toid, \PDO::PARAM_STR);
$stmt->bindParam(2, $query, \PDO::PARAM_STR);
$stmt->bindParam(3, $query, \PDO::PARAM_STR);
$stmt->bindParam(4, $query, \PDO::PARAM_STR);
$stmt->execute();
return $stmt->fetchAll();
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment