This is actually related to another attribute of the PDO connection, which you may not have considered yet. And this is PDO::ATTR_EMULATE_PREPARES
If you add this attribute and set it to false , it will report that the PDO extension will issue prepare to the database for compilation planning, optimization, and planning at the moment you issue ->prepare() . If you leave it unchecked, it will default to true , which tells the EMULATE compilation extension. In other words, it will wait until you issue ->execute() before compiling the statement and error messages.
PDO :: ATTR_EMULATE_PREPARES Enables or disables emulation of prepared statements. Some drivers do not support native prepared statements or have limited support for them. Use this parameter to force the PDO to either always imitate prepared statements (if TRUE), or try to use its own prepared statements (if FALSE). It will always return to emulation of the prepared statement if the driver cannot successfully prepare the current request.
So, run your code with this optional Attribute parameter and you will see the difference.
try { $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass); $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); $DBH->setAttribute( PDO::ATTR_EMULATE_PREPARES, FALSE );
Now you will receive a message and the file will be created with an error message
source share