php-src/ext/pdo_mysql/tests/pdo_mysql_subclass.phpt

101 lines
2.7 KiB
Plaintext
Raw Normal View History

--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
2020-02-03 21:52:20 +00:00
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
2020-02-03 21:52:20 +00:00
try {
2020-02-03 21:52:20 +00:00
class MyPDO extends PDO {
2020-02-03 21:52:20 +00:00
public function __construct() {
$this->protocol();
return call_user_func_array(array($this, 'parent::__construct'), func_get_args());
}
2020-02-03 21:52:20 +00:00
public function exec($statement) {
$this->protocol();
return parent::exec($statement);
}
2020-07-20 14:15:21 +00:00
public function query(...$args) {
2020-02-03 21:52:20 +00:00
$this->protocol();
2020-07-20 14:15:21 +00:00
return parent::query(...$args);
2020-02-03 21:52:20 +00:00
}
2020-02-03 21:52:20 +00:00
public function __call($method, $args) {
print "__call(".var_export($method,true).", ".var_export($args, true).")\n";
// $this->protocol();
}
2020-02-03 21:52:20 +00:00
private function protocol() {
$stack = debug_backtrace();
if (!isset($stack[1]))
return;
2020-02-03 21:52:20 +00:00
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");
}
2020-02-03 21:52:20 +00:00
}
2020-02-03 21:52:20 +00:00
$db = new MyPDO(PDO_MYSQL_TEST_DSN, PDO_MYSQL_TEST_USER, PDO_MYSQL_TEST_PASS);
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
2020-02-03 21:52:20 +00:00
$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();
2020-02-03 21:52:20 +00:00
} catch (PDOException $e) {
printf("[001] %s [%s] %s\n",
$e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
}
2020-02-03 21:52:20 +00:00
$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) {
2016-11-22 21:12:07 +00:00
["id"]=>
string(1) "1"
}
[1]=>
array(1) {
2016-11-22 21:12:07 +00:00
["id"]=>
string(1) "2"
}
}
bool(false)
__call('intercept_call', array (
))
exec('DROP TABLE IF EXISTS test')
done!