I need to use dynamic table names which can't be provided as parameters in prepared statements. I figured that if I restrict identifier names to alphanumeric + underscore only, then there is no way some sql could be injected, right?
here's the check function:
function is_safe_identifier($s) {
return preg_match('/^[a-zA-Z0-9_]+$/', $s) == 1;
}