Our Scripts Vault contains many game scripts that you can use to create your own game!
Reasons to use prepared statementsThe point about escaping data is also very nebulous: Unless you're writing very large blocks of text to the database, escaping strings is typically a non-issue. Most libraries have put a lot of effort into making it cheap, and odds-on it is not the bottleneck.
* PS protect against against most forms of SQL injection, because the programmer does not need to remember to escape stuff.
Reasons not to use prepared statements* An extra network round trip is required between application and database if the PS is a once off query and not reused.
* Some SQL statements can not be prepared, so you may have to mix and match PS and text queries in your source code anyway! This is database and client library specific.
I think the decision between PS and text queries is less important than many think. A well designed application will somehow encapsulate database access behind an API or a Class so that 90% of the application source code should not have queries in it anyway, just calls to the backend...
It's that you not only have to remember to do it, but you also have to remember which data has been escaped already and which data has not.
"Most"? SQL placeholders and prepared statements send the structure of the query (the statement) and the data (placeholder values) to the database engine via completely separate channels and at completely different times (the "extra round trip to the database" that some complain about). This means that, barring severe bugs in the database library, there is absolutely no way that the database engine could be tricked into interpreting data as an SQL command. This technique makes SQL injection (theoretically) impossible; if you're aware of any cases where SQL injection attacks have been successfully made using data passed via an SQL placeholder, I would be extremely interested to hear about them.
Quote from: aerosuidae on October 22, 2010, 10:24:38 PM* An extra network round trip is required between application and database if the PS is a once off query and not reused.This is something of a red herring, IMO. If your load is heavy enough for this to be relevant, then you should be running in a persistent environment (assuming web apps here, the cost of starting up a new instance of the app to handle each incoming request is far greater than the cost of a few extra round trips to the database) and, in a persistent environment, prepared queries can be reused from one request to the next. If each process is allowed to handle 1,000 requests before being killed off, then even a query used by only 1% of requests will be prepared once and executed (on average) 10 times.
* An extra network round trip is required between application and database if the PS is a once off query and not reused.