I think there is no other way to do it like this:
class SQLValidation
{
const PATTERN_SQL_VALID_COMMENT = '~((\/\*).*?(\*\/))~ismu';
const PATTERN_SQL_NOT_VALID = '~\bselect\b.*?(\*|\.\*).*?(?=\bfrom\b)~ismu';
public static function hasStarSelector($queryString)
{
$sql_without_comments = preg_replace(
self::PATTERN_SQL_VALID_COMMENT,
'',
$queryString
);
return (
preg_match(
self::PATTERN_SQL_NOT_VALID, $sql_without_comments)
) ?
true :
false;
}
}