function add_quote_identifier($field, $driver = 'mysql'){ switch ($driver) { case 'mysql': return sprintf('`%s`', $field); case 'sqlite': return sprintf('"%s"', $field); default: return $field;
}
}
然后再利用他来prepare statement:
$stmt = $dbh->prepare(sprintf('SELECT * FROM table_name ORDER BY %s ASC', add_quote_identifier('order')));