I've been reading up on SQL injections and I couldn't find an answer to this question.
I understand if I a query like this
prepare("SELECT id, foo, bar FROM table WHERE username = ?");
Then I should use bind_param('s', $username)
to avoid SQL injection possibilities.
But what if I running my query on something that is not user-inputted but something like an auto-generated ID. Example:
prepare("SELECT username, foo, bar from table where id = ?");
Where id is self-generated (auto-incremented value). Do I have to make use of bind_param('i', $id)
here too or can I just prepare the query as:
prepare("SELECT username, foo, bar from table where id = '$id'");
If bind_param();
is needed, why?
Thanks!