Annotation of embedaddon/php/ext/pdo/tests/pdo_029.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: PDO Common: extending PDO (3)
! 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: function execute($params = array())
! 38: {
! 39: echo __METHOD__ . "()\n";
! 40: parent::execute();
! 41: }
! 42: }
! 43:
! 44: class PDODatabase extends PDO
! 45: {
! 46: function __destruct()
! 47: {
! 48: echo __METHOD__ . "()\n";
! 49: }
! 50:
! 51: function query($sql)
! 52: {
! 53: echo __METHOD__ . "()\n";
! 54: $stmt = $this->prepare($sql, array(PDO::ATTR_STATEMENT_CLASS=>array('PDOStatementx', array($this))));
! 55: $stmt->setFetchMode(PDO::FETCH_ASSOC);
! 56: $stmt->execute();
! 57: return $stmt;
! 58: }
! 59: }
! 60:
! 61: $db = PDOTest::factory('PDODatabase');
! 62: var_dump(get_class($db));
! 63:
! 64: $db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
! 65:
! 66: $stmt = $db->prepare("INSERT INTO test VALUES(?, ?, ?)");
! 67: var_dump(get_class($stmt));
! 68: foreach ($data as $row) {
! 69: $stmt->execute($row);
! 70: }
! 71:
! 72: unset($stmt);
! 73:
! 74: echo "===QUERY===\n";
! 75:
! 76: $stmt = $db->query('SELECT * FROM test');
! 77: var_dump(get_class($stmt));
! 78: var_dump(get_class($stmt->dbh));
! 79:
! 80: echo "===FOREACH===\n";
! 81:
! 82: foreach($stmt as $obj) {
! 83: var_dump($obj);
! 84: }
! 85:
! 86: echo "===DONE===\n";
! 87: exit(0);
! 88: ?>
! 89: --EXPECT--
! 90: string(11) "PDODatabase"
! 91: string(12) "PDOStatement"
! 92: ===QUERY===
! 93: PDODatabase::query()
! 94: PDOStatementX::__construct()
! 95: PDOStatementX::execute()
! 96: string(13) "PDOStatementX"
! 97: string(11) "PDODatabase"
! 98: ===FOREACH===
! 99: array(3) {
! 100: ["id"]=>
! 101: string(2) "10"
! 102: ["val"]=>
! 103: string(3) "Abc"
! 104: ["val2"]=>
! 105: string(3) "zxy"
! 106: }
! 107: array(3) {
! 108: ["id"]=>
! 109: string(2) "20"
! 110: ["val"]=>
! 111: string(3) "Def"
! 112: ["val2"]=>
! 113: string(3) "wvu"
! 114: }
! 115: array(3) {
! 116: ["id"]=>
! 117: string(2) "30"
! 118: ["val"]=>
! 119: string(3) "Ghi"
! 120: ["val2"]=>
! 121: string(3) "tsr"
! 122: }
! 123: ===DONE===
! 124: PDOStatementX::__destruct()
! 125: PDODatabase::__destruct()
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>