There is no javascript code that can successfully protect from sql injection. That kid of protection should be done on the server-side.
If using PHP, you would ensure that magic quotes are removed from values, and then you would cast them to numeric values or pass strings through mysql_real_escape_string.
No it isnt the only way. Using mysqli with prepare statements is a perfectly usable alternative.
Both of these have the advantage over ALL other methods in that they keep the data completely separate from the SQL and so it is impossible to inject anything into the SQL through the data. Thus no PHP is required to prevent SQL injection when you use either of these methods.
I agree with felgall. Using PDO has its benefits (multiple database abstraction) however, if mysql is your only DB. Then mysqli prepare stateent is a suitable choice.
mysqli is probably faster then PDO if you are just dealing with mysql by itself. * Although do not quote me on this.
That was a mis-post on my part; I meant to post a generic page relating to PHP Prepared Statements, and didn’t realize that one was PDO specific. As I’m someone who uses MySQLi for my own projects, I definitely agree with you!