1--TEST-- 2MySQL PDOStatement->execute()/fetch(), Non-SELECT 3--EXTENSIONS-- 4pdo_mysql 5--SKIPIF-- 6<?php 7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc'); 8MySQLPDOTest::skip(); 9?> 10--FILE-- 11<?php 12 require_once(__DIR__ . DIRECTORY_SEPARATOR . '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('DROP TABLE IF EXISTS test'); 57 $db->exec('CREATE TABLE test(id INT)'); 58 $db->exec('INSERT INTO test(id) VALUES (1), (2)'); 59 $stmt = $db->query('SELECT * FROM test ORDER BY id ASC'); 60 var_dump($stmt->fetchAll(PDO::FETCH_ASSOC)); 61 var_dump($stmt->fetch()); 62 $db->intercept_call(); 63 64 65 } catch (PDOException $e) { 66 printf("[001] %s [%s] %s\n", 67 $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); 68 } 69 70 $db->exec('DROP TABLE IF EXISTS test'); 71 print "done!\n"; 72?> 73--CLEAN-- 74<?php 75require __DIR__ . '/mysql_pdo_test.inc'; 76$db = MySQLPDOTest::factory(); 77$db->exec('DROP TABLE IF EXISTS test'); 78?> 79--EXPECTF-- 80__construct('%S', '%S', %s) 81exec('DROP TABLE IF EXISTS test') 82exec('CREATE TABLE test(id INT)') 83exec('INSERT INTO test(id) VALUES (1), (2)') 84query('SELECT * FROM test 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') 101done! 102