So I was wondering is this enough to be safe that user won’t do any SQL injections and the number will be only and always integer? The $id in getArticle function is binded to SQL query.
<?php $id = (isset($_GET['id']) && is_int((int)$_GET['id'])) ? (int)$_GET['id'] : false ?>
<?php $news = $class->getArticle($id) ?>
As far I tested it worked fine, but as I’m not totally sure I rather ask you guyz!
Ok, people say prepared statements would do the trick. They really would? Like, can I be totally sure that if bind param as integer it will be integer nothing else?
Thanks in advance!
You can simply type cast them to proper type:
To make sure that you get what you are expecting.
The better solution is to use Prepared statements to avoid sql injection.