$term = "foo' bar";
$term_escaped = mysql_real_escape_string($term);
$sql = mysql_query("SELECT * FROM artists WHERE artist_name LIKE '%$term_escaped%'") or die ( mysql_error() );
But you should start using PDO instead of the deprecated mysql extension in PHP. You don't need to escape values when you use query parameters with PDO:
$term = "foo' bar";
$stmt = $pdo->prepare("SELECT * FROM artists WHERE artist_name LIKE CONCAT('%',?,'%')");
if ($stmt === false) {
die(print_r($pdo->errorInfo(), true));
}
if ($stmt->execute(array($term)) === false) {
die(print_r($stmt->errorInfo(), true));
}
Re your updated question:
It sounds like you are asking about the opposite of your original question, that is some of you data contains a literal single-quote character, and you want to search for matches that don't have the quote character.
Just don't use the quote character in the pattern you search for with LIKE.
WHERE artist_name LIKE '%foo bar%'
You should understand that the SQL LIKE predicate is not full-text search. It only searches for the sequence of characters in your pattern string, including white space and punctuation and so on. If you don't use those extra characters, data that contains those characters doesn't match.
PS: since you are using the LIKE '%word%'
pattern, you should be aware that this will be very slow as your data grows. See my presentation Full Text Search Throwdown.