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