bug79132.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --TEST--
  2. Bug #79132: PDO re-uses parameter values from earlier calls to execute()
  3. --EXTENSIONS--
  4. pdo_mysql
  5. --SKIPIF--
  6. <?php
  7. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  8. MySQLPDOTest::skip();
  9. ?>
  10. --FILE--
  11. <?php
  12. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  13. $pdo = MySQLPDOTest::factory();
  14. $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15. $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
  16. test($pdo);
  17. echo "\n";
  18. $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  19. test($pdo);
  20. function test($pdo) {
  21. $stmt = $pdo->prepare('select ? a, ? b');
  22. $set = [
  23. ['a', 'b'],
  24. ['x'], /* second parameter is missing */
  25. [1 => 'y'], /* first parameter is missing */
  26. ];
  27. foreach ($set as $params) {
  28. try {
  29. var_dump($stmt->execute($params), $stmt->fetchAll(PDO::FETCH_ASSOC));
  30. } catch (PDOException $error) {
  31. echo $error->getMessage() . "\n";
  32. }
  33. }
  34. }
  35. ?>
  36. --EXPECT--
  37. bool(true)
  38. array(1) {
  39. [0]=>
  40. array(2) {
  41. ["a"]=>
  42. string(1) "a"
  43. ["b"]=>
  44. string(1) "b"
  45. }
  46. }
  47. SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
  48. SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
  49. bool(true)
  50. array(1) {
  51. [0]=>
  52. array(2) {
  53. ["a"]=>
  54. string(1) "a"
  55. ["b"]=>
  56. string(1) "b"
  57. }
  58. }
  59. SQLSTATE[HY093]: Invalid parameter number
  60. SQLSTATE[HY093]: Invalid parameter number