Using question marks as anonymous placeholders


show more Using question marks as anonymous placeholders provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP show less
please wait ...

Using question marks as anonymous placeholders

We've just seen how to use named parameters in a PDO prepared statement. You can also use question marks as placeholders, or anonymous parameters. Continue working with the file from the previous video. Alternatively, open pdo_anonymous.php, which you can find in the chapter three 03_03 folder of the Exercise Files. The where clause in the SQL uses named parameters, which all begin with a colon. There are three of them. :make, :yearmade and :price.

Anonymous parameters use a question mark as the placeholder. So to replace these with anonymous placeholders, just change :make to a question mark, and do the same with the two other named parameters. Because they're anonymous, you can't use the name as the first argument to the bindValue or bindParam methods. What you need to do is to use the position that the parameter has inside the SQL counting from one. So make is one, yearmade is two and price is three.

So we just change those values down here to one, two, three. And that's all there is...

Using question marks as anonymous placeholders
Video duration: 2m 35s 3h 47m Intermediate

Viewers:

Using question marks as anonymous placeholders provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...