Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO quote method

Tags:

php

mysql

pdo

Where and when do you use the quote method in PDO? I'm asking this in the light of the fact that in PDO, all quoting is done by the PDO object therefore no user input should be escaped/quoted etc. This makes one wonder why worry about a quote method if it's not gonna get used in a prepared statement anyway?

like image 566
Average Joe Avatar asked Feb 12 '12 16:02

Average Joe


1 Answers

When using Prepared Statements with PDO::prepare() and PDOStatement::execute(), you don't have any quoting to do : this will be done automatically.

But, sometimes, you will not (or cannot) use prepared statements, and will have to write full SQL queries and execute them with PDO::exec() ; in those cases, you will have to make sure strings are quoted properly -- this is when the PDO::quote() method is useful.

like image 90
Pascal MARTIN Avatar answered Sep 22 '22 09:09

Pascal MARTIN