bug62593.phpt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. PDO PgSQL Bug #62593 (Emulate prepares behave strangely with PARAM_BOOL)
  3. --EXTENSIONS--
  4. pdo
  5. pdo_pgsql
  6. --SKIPIF--
  7. <?php
  8. require __DIR__ . '/config.inc';
  9. require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
  10. PDOTest::skip();
  11. ?>
  12. --FILE--
  13. <?php
  14. require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
  15. $db = PDOTest::test_factory(__DIR__ . '/common.phpt');
  16. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
  17. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
  18. $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
  19. $errors = array();
  20. $value = true;
  21. $query = $db->prepare('SELECT :foo IS FALSE as val_is_false');
  22. $query->bindValue(':foo', $value, PDO::PARAM_BOOL);
  23. $query->execute();
  24. $errors[] = $query->errorInfo();
  25. var_dump($value);
  26. $query->bindValue(':foo', 0, PDO::PARAM_BOOL);
  27. $query->execute();
  28. $errors[] = $query->errorInfo();
  29. // Verify bindParam maintains reference and only passes when execute is called
  30. $value = true;
  31. $query->bindParam(':foo', $value, PDO::PARAM_BOOL);
  32. $value = false;
  33. $query->execute();
  34. $errors[] = $query->errorInfo();
  35. var_dump($value);
  36. // Try with strings - Bug #68351
  37. $value = '0';
  38. $query->bindParam(':foo', $value, PDO::PARAM_BOOL);
  39. $query->execute();
  40. $errors[] = $query->errorInfo();
  41. var_dump($query->fetchColumn());
  42. $value = "abc";
  43. $query->bindParam(':foo', $value, PDO::PARAM_BOOL);
  44. $query->execute();
  45. $errors[] = $query->errorInfo();
  46. var_dump($query->fetchColumn());
  47. $expect = 'No errors found';
  48. foreach ($errors as $error)
  49. {
  50. if (null !== $error[2] && strpos('Invalid text representation', $error[2]) !== false)
  51. {
  52. $expect = 'Invalid boolean found';
  53. }
  54. }
  55. echo $expect;
  56. ?>
  57. --EXPECT--
  58. bool(true)
  59. bool(false)
  60. bool(true)
  61. bool(false)
  62. No errors found