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