Annotation of embedaddon/php/ext/pdo/tests/pdo_026.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: PDO Common: extending PDO (2)
! 3: --SKIPIF--
! 4: <?php # vim:ft=php
! 5: if (!extension_loaded('pdo')) die('skip');
! 6: $dir = getenv('REDIR_TEST_DIR');
! 7: if (false == $dir) die('skip no driver');
! 8: require_once $dir . 'pdo_test.inc';
! 9: PDOTest::skip();
! 10: ?>
! 11: --FILE--
! 12: <?php
! 13: if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
! 14: require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
! 15:
! 16: $data = array(
! 17: array('10', 'Abc', 'zxy'),
! 18: array('20', 'Def', 'wvu'),
! 19: array('30', 'Ghi', 'tsr'),
! 20: );
! 21:
! 22: class PDOStatementX extends PDOStatement
! 23: {
! 24: public $dbh;
! 25:
! 26: protected function __construct($dbh)
! 27: {
! 28: $this->dbh = $dbh;
! 29: echo __METHOD__ . "()\n";
! 30: }
! 31:
! 32: function __destruct()
! 33: {
! 34: echo __METHOD__ . "()\n";
! 35: }
! 36: }
! 37:
! 38: class PDODatabase extends PDO
! 39: {
! 40: function __destruct()
! 41: {
! 42: echo __METHOD__ . "()\n";
! 43: }
! 44:
! 45: function query($sql)
! 46: {
! 47: echo __METHOD__ . "()\n";
! 48: $stmt = $this->prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('PDOStatementx', array($this))));
! 49: $stmt->setFetchMode(PDO::FETCH_ASSOC);
! 50: $stmt->execute();
! 51: return $stmt;
! 52: }
! 53: }
! 54:
! 55: $db = PDOTest::factory('PDODatabase');
! 56: var_dump(get_class($db));
! 57:
! 58: $db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
! 59:
! 60: $stmt = $db->prepare("INSERT INTO test VALUES(?, ?, ?)");
! 61: var_dump(get_class($stmt));
! 62: foreach ($data as $row) {
! 63: $stmt->execute($row);
! 64: }
! 65:
! 66: unset($stmt);
! 67:
! 68: $stmt = $db->query('SELECT * FROM test');
! 69: var_dump(get_class($stmt));
! 70: var_dump(get_class($stmt->dbh));
! 71:
! 72: foreach($stmt as $obj) {
! 73: var_dump($obj);
! 74: }
! 75:
! 76: echo "===DONE===\n";
! 77: ?>
! 78: --EXPECT--
! 79: string(11) "PDODatabase"
! 80: string(12) "PDOStatement"
! 81: PDODatabase::query()
! 82: PDOStatementX::__construct()
! 83: string(13) "PDOStatementX"
! 84: string(11) "PDODatabase"
! 85: array(3) {
! 86: ["id"]=>
! 87: string(2) "10"
! 88: ["val"]=>
! 89: string(3) "Abc"
! 90: ["val2"]=>
! 91: string(3) "zxy"
! 92: }
! 93: array(3) {
! 94: ["id"]=>
! 95: string(2) "20"
! 96: ["val"]=>
! 97: string(3) "Def"
! 98: ["val2"]=>
! 99: string(3) "wvu"
! 100: }
! 101: array(3) {
! 102: ["id"]=>
! 103: string(2) "30"
! 104: ["val"]=>
! 105: string(3) "Ghi"
! 106: ["val2"]=>
! 107: string(3) "tsr"
! 108: }
! 109: ===DONE===
! 110: PDOStatementX::__destruct()
! 111: PDODatabase::__destruct()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>