Annotation of embedaddon/php/ext/pdo/tests/pdo_023.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: PDO Common: extending PDO
! 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: class PDOStatementX extends PDOStatement
! 17: {
! 18: public $test1 = 1;
! 19:
! 20: protected function __construct()
! 21: {
! 22: $this->test2 = 2;
! 23: $this->test2 = 22;
! 24: echo __METHOD__ . "()\n";
! 25: }
! 26:
! 27: function __destruct()
! 28: {
! 29: echo __METHOD__ . "()\n";
! 30: }
! 31: }
! 32:
! 33: class PDODatabaseX extends PDO
! 34: {
! 35: public $test1 = 1;
! 36:
! 37: function __destruct()
! 38: {
! 39: echo __METHOD__ . "()\n";
! 40: }
! 41:
! 42: function test()
! 43: {
! 44: $this->test2 = 2;
! 45: var_dump($this->test1);
! 46: var_dump($this->test2);
! 47: $this->test2 = 22;
! 48: }
! 49:
! 50: function query($sql)
! 51: {
! 52: echo __METHOD__ . "()\n";
! 53: $stmt = parent::prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('PDOStatementx')));
! 54: $stmt->execute();
! 55: return $stmt;
! 56: }
! 57: }
! 58:
! 59: $db = PDOTest::factory('PDODatabaseX');
! 60: $db->test();
! 61: var_dump($db);
! 62:
! 63: $db->query('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))');
! 64: $db->query('INSERT INTO test VALUES(0, \'A\')');
! 65: $db->query('INSERT INTO test VALUES(1, \'B\')');
! 66:
! 67:
! 68: $stmt = $db->query('SELECT val, id FROM test');
! 69: var_dump($stmt);
! 70: var_dump($stmt->fetchAll(PDO::FETCH_COLUMN|PDO::FETCH_UNIQUE));
! 71:
! 72: $stmt = NULL;
! 73: $db = NULL;
! 74:
! 75:
! 76: ?>
! 77: --EXPECTF--
! 78: int(1)
! 79: int(2)
! 80: object(PDODatabaseX)#%d (2) {
! 81: ["test1"]=>
! 82: int(1)
! 83: ["test2"]=>
! 84: int(22)
! 85: }
! 86: PDODatabaseX::query()
! 87: PDOStatementX::__construct()
! 88: PDOStatementX::__destruct()
! 89: PDODatabaseX::query()
! 90: PDOStatementX::__construct()
! 91: PDOStatementX::__destruct()
! 92: PDODatabaseX::query()
! 93: PDOStatementX::__construct()
! 94: PDOStatementX::__destruct()
! 95: PDODatabaseX::query()
! 96: PDOStatementX::__construct()
! 97: object(PDOStatementX)#%d (3) {
! 98: ["test1"]=>
! 99: int(1)
! 100: ["queryString"]=>
! 101: string(24) "SELECT val, id FROM test"
! 102: ["test2"]=>
! 103: int(22)
! 104: }
! 105: array(2) {
! 106: ["A"]=>
! 107: string(1) "0"
! 108: ["B"]=>
! 109: string(1) "1"
! 110: }
! 111: PDOStatementX::__destruct()
! 112: PDODatabaseX::__destruct()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>