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