pdo_mysql_subclass.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. --TEST--
  2. MySQL PDOStatement->execute()/fetch(), Non-SELECT
  3. --SKIPIF--
  4. <?php
  5. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
  6. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  7. MySQLPDOTest::skip();
  8. if (version_compare(PHP_VERSION, '5.0.0', '<'))
  9. die("skip Requires PHP 5.0+");
  10. ?>
  11. --FILE--
  12. <?php
  13. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  14. // No silly strict mode warnings, please!
  15. error_reporting(E_ALL^E_STRICT);
  16. ini_set('display_errors', false);
  17. try {
  18. class MyPDO extends PDO {
  19. public function __construct() {
  20. $this->protocol();
  21. return call_user_func_array(array($this, 'parent::__construct'), func_get_args());
  22. }
  23. public function exec() {
  24. $this->protocol();
  25. return call_user_func_array(array($this, 'parent::exec'), func_get_args());
  26. }
  27. public function query() {
  28. $this->protocol();
  29. return call_user_func_array(array($this, 'parent::query'), func_get_args());
  30. }
  31. public function __call($method, $args) {
  32. print "__call(".var_export($method,true).", ".var_export($args, true).")\n";
  33. // $this->protocol();
  34. }
  35. private function protocol() {
  36. $stack = debug_backtrace();
  37. if (!isset($stack[1]))
  38. return;
  39. printf("%s(", $stack[1]['function']);
  40. $args = '';
  41. foreach ($stack[1]['args'] as $k => $v)
  42. $args .= sprintf("%s, ", var_export($v, true));
  43. if ($args != '')
  44. printf("%s", substr($args, 0, -2));
  45. printf(")\n");
  46. }
  47. }
  48. $db = new MyPDO(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS);
  49. $db->exec('DROP TABLE IF EXISTS test');
  50. $db->exec('CREATE TABLE test(id INT)');
  51. $db->exec('INSERT INTO test(id) VALUES (1), (2)');
  52. $stmt = $db->query('SELECT * FROM test ORDER BY id ASC');
  53. var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
  54. var_dump($stmt->fetch());
  55. $db->intercept_call();
  56. } catch (PDOException $e) {
  57. printf("[001] %s [%s] %s\n",
  58. $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
  59. }
  60. $db->exec('DROP TABLE IF EXISTS test');
  61. print "done!\n";
  62. ?>
  63. --CLEAN--
  64. <?php
  65. require dirname(__FILE__) . '/mysql_pdo_test.inc';
  66. $db = MySQLPDOTest::factory();
  67. $db->exec('DROP TABLE IF EXISTS test');
  68. ?>
  69. --EXPECTF--
  70. __construct('%S', '%S', %s)
  71. exec('DROP TABLE IF EXISTS test')
  72. exec('CREATE TABLE test(id INT)')
  73. exec('INSERT INTO test(id) VALUES (1), (2)')
  74. query('SELECT * FROM test ORDER BY id ASC')
  75. array(2) {
  76. [0]=>
  77. array(1) {
  78. [%u|b%"id"]=>
  79. %unicode|string%(1) "1"
  80. }
  81. [1]=>
  82. array(1) {
  83. [%u|b%"id"]=>
  84. %unicode|string%(1) "2"
  85. }
  86. }
  87. bool(false)
  88. __call('intercept_call', array (
  89. ))
  90. exec('DROP TABLE IF EXISTS test')
  91. done!