Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I still Need To Use Prepared Statement [duplicate]

Using PHP and MySQLi I have a simple form with 4 HTML 5 Dropdown Select list inputs. Now wondering do I still have to use Prepared Statement to secure my database? Am I still in the risk of SQL Injection issues? Or is there any other type of risk for using this type of inputs. Thanks

like image 442
Suffii Avatar asked Sep 07 '14 16:09

Suffii


People also ask

Should I always use prepared statements?

You should always prefer working with prepared statements for the security benefits. They all but eliminate vulnerability to SQL injection, without you having to worry about SQL-escaping values. If you have a query that doesn't run often, though (less than once per request), a prepared statement can take longer to run.

Why do we use prepared statement instead of statement?

If you want to execute a Statement object many times, it usually reduces execution time to use a PreparedStatement object instead. The main feature of a PreparedStatement object is that, unlike a Statement object, it is given a SQL statement when it is created.

What are the limitation of prepared statement?

Following are the limitations of prepared statements: Since a PreparedStatement object represents only one SQL statement at a time, we can execute only one statement by one prepared statement object. To prevent injection attacks it does not allow more than one value to a place holder.

How much faster are prepared statements?

Prepared statements are much faster when you have to run the same statement multiple times, with different data. Thats because SQL will validate the query only once, whereas if you just use a statement it will validate the query each time.


1 Answers

You are still wide open for an injection attack since the value inserted through your select box could easly be modifed by the end user.

If you have a good validation server side, then doing it without prepared statement would work.

With good i mean something like this:

$array = Array("all", "your", "possible", "values", "from", "Select boxes");
if(in_array ($_POST['selectbox'], $array)){
      //Mysql statements etc....
}

Directly inserting user input is NEVER a good idea. You should never trust the end user!

like image 172
Philip G Avatar answered Sep 23 '22 10:09

Philip G