From f982890a5886e4383805b2a75ef0537e85542cda Mon Sep 17 00:00:00 2001 From: Marcus Boerger Date: Thu, 24 Feb 2005 00:14:50 +0000 Subject: - Missed during last committs somehow --- ext/pdo/tests/pdo_014.inc | 61 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 ext/pdo/tests/pdo_014.inc (limited to 'ext/pdo/tests/pdo_014.inc') diff --git a/ext/pdo/tests/pdo_014.inc b/ext/pdo/tests/pdo_014.inc new file mode 100755 index 0000000000..ed6fd06f47 --- /dev/null +++ b/ext/pdo/tests/pdo_014.inc @@ -0,0 +1,61 @@ +exec($SQL['create']); +$DB->exec($SQL['insert1']); +$DB->exec($SQL['insert2']); + +class Test +{ + function __construct($name = 'N/A') + { + echo __METHOD__ . "($name)\n"; + } +} + +$stmt = $DB->query($SQL['select1'], PDO_FETCH_CLASS, 'Test', array('WOW')); + +$it = new IteratorIterator($stmt); /* check if we can convert that thing */ + +/*** HINT: If YOU plan to do so remember not to call rewind() -> see below ***/ + +foreach($it as $data) +{ + var_dump($data); +} + +$it->next(); /* must be allowed */ +var_dump($it->current()); /* must return NULL */ +var_dump($it->valid()); /* must return false */ + +class PDOStatementAggregate extends PDOStatement implements IteratorAggregate +{ + private function __construct() + { + echo __METHOD__ . "\n"; + $this->setFetchMode(PDO_FETCH_NUM); + /* default fetch mode is BOTH, so we see if the ctor can overwrite that */ + } + + function getIterator() + { + echo __METHOD__ . "\n"; + $this->execute(); + return new IteratorIterator($this, 'PDOStatement'); + } +} + +$stmt = $DB->prepare($SQL['select1'], array(PDO_ATTR_STATEMENT_CLASS=>array('PDOStatementAggregate'))); + +foreach($stmt as $data) +{ + var_dump($data); +} + +?> -- cgit v1.2.1