For the asked question it's a perfectly valid and a safe answer. Whoever complains it's not safe - how about a deal that I set up this particular code with the
$galleries
as provided in the question and you exploit it using aforementioned "sql injection vulnerability". If you cannot - you pay me USD200. How about that? — zerkms 15 hours ago