summaryrefslogtreecommitdiff
path: root/ext/pdo/tests/pdo_014.inc
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2005-02-24 00:14:50 +0000
committerMarcus Boerger <helly@php.net>2005-02-24 00:14:50 +0000
commitf982890a5886e4383805b2a75ef0537e85542cda (patch)
treed2dc5fcba4047a304779d8fcb83d3a78412fcd2f /ext/pdo/tests/pdo_014.inc
parent30f870f957d4b1918afa0b826dd96eac0b9bba89 (diff)
downloadphp-git-f982890a5886e4383805b2a75ef0537e85542cda.tar.gz
- Missed during last committs somehow
Diffstat (limited to 'ext/pdo/tests/pdo_014.inc')
-rwxr-xr-xext/pdo/tests/pdo_014.inc61
1 files changed, 61 insertions, 0 deletions
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 @@
+<?php # vim:ft=php
+
+require_once('pdo.inc');
+
+set_sql('create', 'CREATE TABLE test(id int PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))');
+set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\', \'Group1\')');
+set_sql('insert2', 'INSERT INTO test VALUES(2, \'B\', \'Group2\')');
+set_sql('select1', 'SELECT val, grp FROM test');
+
+$DB->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);
+}
+
+?>