debug_emulated_prepares.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --TEST--
  2. PDO Common: PDOStatement::debugDumpParams() with emulated prepares
  3. --EXTENSIONS--
  4. pdo
  5. --SKIPIF--
  6. <?php
  7. $dir = getenv('REDIR_TEST_DIR');
  8. if (false == $dir) die('skip no driver');
  9. require_once $dir . 'pdo_test.inc';
  10. PDOTest::skip();
  11. $db = PDOTest::factory();
  12. if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'pgsql') die('skip pgsql has its own test for this feature');
  13. if (!@$db->getAttribute(PDO::ATTR_EMULATE_PREPARES) && !@$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true)) die('skip driver cannot emulate prepared statements');
  14. ?>
  15. --FILE--
  16. <?php
  17. if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
  18. require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
  19. $db = PDOTest::factory();
  20. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
  21. $stmt = $db->query('SELECT 1');
  22. // "Sent SQL" shouldn't display
  23. var_dump($stmt->debugDumpParams());
  24. $stmt = $db->prepare('SELECT :bool, :int, :string, :null');
  25. $stmt->bindValue(':bool', true, PDO::PARAM_BOOL);
  26. $stmt->bindValue(':int', 123, PDO::PARAM_INT);
  27. $stmt->bindValue(':string', 'foo', PDO::PARAM_STR);
  28. $stmt->bindValue(':null', null, PDO::PARAM_NULL);
  29. $stmt->execute();
  30. // "Sent SQL" should display
  31. var_dump($stmt->debugDumpParams());
  32. ?>
  33. --EXPECT--
  34. SQL: [8] SELECT 1
  35. Params: 0
  36. NULL
  37. SQL: [34] SELECT :bool, :int, :string, :null
  38. Sent SQL: [26] SELECT 1, 123, 'foo', NULL
  39. Params: 4
  40. Key: Name: [5] :bool
  41. paramno=-1
  42. name=[5] ":bool"
  43. is_param=1
  44. param_type=5
  45. Key: Name: [4] :int
  46. paramno=-1
  47. name=[4] ":int"
  48. is_param=1
  49. param_type=1
  50. Key: Name: [7] :string
  51. paramno=-1
  52. name=[7] ":string"
  53. is_param=1
  54. param_type=2
  55. Key: Name: [5] :null
  56. paramno=-1
  57. name=[5] ":null"
  58. is_param=1
  59. param_type=0
  60. NULL