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