The most common suggestion for protection against MySQL injection is prepared statements (either from PDO of mysqli). Say for whatever reason, I can't use prepared statemnets...how do I protect my data?
I would love to create a function like the following...
function cleanse($val) {
global $db;
$val = $db->real_escape_string($val);
return $val;
}
//Then I use it like
$sql = "select abc from dyf where z='".cleanse($_GET['id'])."'";
$db->query($sql); //etc...
But I'm not sure if that stops 1=1 attacks and attacks from strange foreign characters.
Is there a bullet proof way to make my cleanse function secure (no prepared functions!)?
Do I need to convert any string to utf-8?
If I wrap all column values in quotes and use mysqli's real_escape_string, am I ok?
Are there any other tricks that would make my cleanse function safe against injection?