PDO Emulation Mode

In the content linked below, Tom says setting id = :id can’t be used, because it has already been used in the query, and each parameter needs a unique name

However, each PDO parameter does not need a unique name if emulation mode is on, according to https://www.php.net/manual/en/pdo.prepare.php

It seems that emulation mode is on by default (using Docker). However, if we add this to the end of the DatabaseConnection.php

$pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );

then emulation mode is off, and we really can’t reuse :id and must set id = :primaryKey’ and set a value for primaryKey.

My question is, what is emulation mode, simply?

Is there any drawback to setting emulation mode explicitly to true, and re-using parameters?

Link to content:  PHP & MySQL: Novice to Ninja, 7th Edition - Section 7

Take a look here: https://phpdelusions.net/pdo#emulation

There are pros and cons of each. Basically if you are not doing anything high volume you won’t notice the difference. Whether one is better in other scenarios depends on your workload and would need to be tested on a per application bqsis.

But, it’s a bad idea to write code that breaks when a setting like this is changed, hence using different names in the book.