I've been reading through the documentation, but I feel like it's always a little bit vague on this, perhaps I'm missing something.
function foomodule_my_hook_menu_callback($unescapedUserInputString) {
$sql = "select name from {foo_table} where bar=:inputString";
$result = db_query($sql, array(':inputString' => $unescapedUserInputString));
}
Is the above code vulnerable to an SQL injection attack? Or will :inputString
get appropriately escaped to make it safe for SQL? (I know I need to sanitize it for proper values in my implementation, but I'm just referring to the SQL safety)
What about with db_insert()?
$insert_id = db_insert('foo_table')
->fields(array(
'name' => $unescapedUserInputString,
))
->execute();