Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any issues with always preparing SQL statements with PHP?

Is there any issue with always preparing SQL statements with PHP instead of executing them directly?

Not sure if database system matters, but it's DB2 on System i.

like image 418
Bead Avatar asked Jul 14 '11 17:07

Bead


People also ask

Should I use PHP prepared statements?

Prepared statements are very useful against SQL injections, because parameter values, which are transmitted later using a different protocol, need not be correctly escaped. If the original statement template is not derived from external input, SQL injection cannot occur.

Should you always use prepared statements?

In reference to the data and storing it, as stated in the comments, you can never and should never trust any user related input. Unless you are 101% sure the data being used to manipulate said databases/values is hard-coded into your app, you must use prepared statements.

When should prepared statements not be used?

It is easy: If you know the string comes from your application and cannot be manipulated by a user, then there is no need for prepared statements, because there is nothing to inject.

Are prepared statements Safe?

A prepared statement is a parameterized and reusable SQL query which forces the developer to write the SQL command and the user-provided data separately. The SQL command is executed safely, preventing SQL Injection vulnerabilities.


1 Answers

You might take a slight performance hit, if they are real prepared statements and not just emulated in the driver. This is because you will have to make two calls to the database, rather than just one.

like image 135
troelskn Avatar answered Oct 01 '22 21:10

troelskn