I'm trying to use the new PHP mysqli extension. I've got a function (safe()) that recursively uses mysql_real_escape_string to make strings safe. How do I use my mysqli connection inside this function to call the mysqli::escape_string() function?
Example:
$db = new mysqli($host,$user,$password,$database_name);
function safe ($data) {
if(!is_array($data)) {
if(!get_magic_quotes_gpc()) {
$data = **mysqli::escape_string($data)**
return $data;
}
} else {
return array_map('safe',$data);
}
}
Where I have mysqli::escape_string() inside safe() how do I call that? Outside of a function it would be $db->escape_string() but I can't find a way to call it insde. I've tried passing $db to the function, making $db global etc. The alternative is to use the procedural mysqli_escape_string() but that requires the mysqli link resource to be explicitly passed to it, but I can't find a way to access that.