0

I have this very simple MCVE where even no table/database is affected:

<?php
$pdoConnection = new PDO( "mysql:host=<hostname>", "<user>", "<pwd>" );
$pdoConnection->setAttribute( PDO::ATTR_EMULATE_PREPARES, TRUE );
$command = $pdoConnection->prepare("SELECT IF('1', -:foo, :foo) AS FOO");
$command->bindValue( "foo", 1, PDO::PARAM_INT );
$command->execute();
echo "<pre>";
print_r($command->fetch(PDO::FETCH_ASSOC));
?>

The result is as expected:

Array
(
    [FOO] => -1
)

Disabling the prepare emulation with
$pdoConnection->setAttribute( PDO::ATTR_EMULATE_PREPARES, TRUE );

breaks totally the code. No error and also no output as nothing has been executed even it is a regular and correct MySQL code.

My questions:

  1. Is there a legal reason why there is no result, or
  2. is it a bug, but what causes the bug? PHP or MySQL?

Versions:

  • OS: SLES 12.3
  • PHP: 7.2.9
  • MySQL 8.0.12
Peter VARGA
  • 4,780
  • 3
  • 39
  • 75
  • 1
    Specially: https://stackoverflow.com/questions/18028706/php-pdoexception-sqlstatehy093-invalid-parameter-number – Progman Sep 16 '18 at 15:18
  • You can't bind the same parameter `:foo` twice without emulated prepares. – mario Sep 16 '18 at 15:22
  • @AlBundy I haven't block the question. When you use a different error reporting as described in the first duplicate you will get the error message "Invalid parameter number", which is described in the second duplicate. – Progman Sep 16 '18 at 15:23

0 Answers0