Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Mysql Auto Quote?

When inserting a row in mysql database, string values need to be enclosed in quotes where integer don't need to.

Is there any class or library that takes care of this automatically so that I can just pass to a 3rd-party function an array of fieldnames and values and don't have to worry about putting string values in quotes?

Thanks,

like image 307
Dave Avatar asked May 01 '26 05:05

Dave


2 Answers

You need to worry about more than just quoting; you need to worry about SQL injection.

For new code, use PDO instead of the mysql_ or mysqli_ functions. Within PDO, use prepared statements (the PDOStatement object).

With prepared statements, you never have to enclose things in quotes and it stops SQL injections.

like image 198
Nate Avatar answered May 02 '26 18:05

Nate


If you use PDO, then you do not need to worry about things like that.

Take a look at PDO::prepare for some examples.

like image 29
Ólafur Waage Avatar answered May 02 '26 19:05

Ólafur Waage



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!