mirror of
https://github.com/php/php-src.git
synced 2024-11-29 04:46:07 +08:00
- Missed during last committs somehow
This commit is contained in:
parent
30f870f957
commit
f982890a58
32
ext/pdo/tests/pdo_012.inc
Executable file
32
ext/pdo/tests/pdo_012.inc
Executable file
@ -0,0 +1,32 @@
|
||||
<?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']);
|
||||
|
||||
$stmt = $DB->query($SQL['select1'], PDO_FETCH_NUM);
|
||||
var_dump($stmt->fetchAll());
|
||||
|
||||
class Test
|
||||
{
|
||||
function __construct($name = 'N/A')
|
||||
{
|
||||
echo __METHOD__ . "($name)\n";
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $DB->query($SQL['select1'], PDO_FETCH_CLASS, 'Test');
|
||||
var_dump($stmt->fetchAll());
|
||||
|
||||
$stmt = $DB->query($SQL['select1'], PDO_FETCH_NUM);
|
||||
$stmt->setFetchMode(PDO_FETCH_CLASS, 'Test', array('Changed'));
|
||||
var_dump($stmt->fetchAll());
|
||||
|
||||
?>
|
39
ext/pdo/tests/pdo_013.inc
Executable file
39
ext/pdo/tests/pdo_013.inc
Executable file
@ -0,0 +1,39 @@
|
||||
<?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']);
|
||||
|
||||
foreach($DB->query($SQL['select1'], PDO_FETCH_NUM) as $data)
|
||||
{
|
||||
var_dump($data);
|
||||
}
|
||||
|
||||
class Test
|
||||
{
|
||||
function __construct($name = 'N/A')
|
||||
{
|
||||
echo __METHOD__ . "($name)\n";
|
||||
}
|
||||
}
|
||||
|
||||
foreach($DB->query($SQL['select1'], PDO_FETCH_CLASS, 'Test') as $data)
|
||||
{
|
||||
var_dump($data);
|
||||
}
|
||||
|
||||
$stmt = $DB->query($SQL['select1'], PDO_FETCH_CLASS, 'Test', array('WOW'));
|
||||
|
||||
foreach($stmt as $data)
|
||||
{
|
||||
var_dump($data);
|
||||
}
|
||||
|
||||
?>
|
61
ext/pdo/tests/pdo_014.inc
Executable file
61
ext/pdo/tests/pdo_014.inc
Executable file
@ -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);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user