remove old test files

This commit is contained in:
Wez Furlong 2005-07-07 15:36:00 +00:00
parent 4580a7fd8e
commit 5fe199fb0f
27 changed files with 0 additions and 1130 deletions

View File

@ -1,20 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'B\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\')');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_ASSOC));
?>

View File

@ -1,21 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'B\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\')');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_NUM));
?>

View File

@ -1,20 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'B\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\')');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_BOTH));
?>

View File

@ -1,20 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'B\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\')');
set_sql('select', 'SELECT * FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$stmt = $DB->query($SQL['select']);
var_dump($stmt->fetchAll(PDO_FETCH_OBJ));
?>

View File

@ -1,38 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\', \'AA\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'B\', \'BB\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\', \'CC\')');
set_sql('select', 'SELECT id, val, val2 FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
class TestBase
{
public $id;
protected $val;
private $val2;
}
class TestDerived extends TestBase
{
protected $row;
public function __construct(&$row)
{
echo __METHOD__ . "($row,{$this->id})\n";
$this->row = $row++;
}
}
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS, 'TestBase'));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS, 'TestDerived', array(0)));
?>

View File

@ -1,20 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'A\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\')');
set_sql('select', 'SELECT val, id FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM|PDO_FETCH_GROUP));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_ASSOC|PDO_FETCH_GROUP));
?>

View File

@ -1,19 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id CHAR(1) NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(\'A\', \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(\'B\', \'A\')');
set_sql('insert3', 'INSERT INTO test VALUES(\'C\', \'C\')');
set_sql('select', 'SELECT id, val FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM|PDO_FETCH_UNIQUE));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_ASSOC|PDO_FETCH_UNIQUE));
?>

View File

@ -1,19 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id CHAR(1) NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(\'A\', \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(\'B\', \'A\')');
set_sql('insert3', 'INSERT INTO test VALUES(\'C\', \'C\')');
set_sql('select', 'SELECT val, id FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM|PDO_FETCH_UNIQUE));
// check that repeated first columns overwrite existing array elements
?>

View File

@ -1,53 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE classtypes(id int NOT NULL PRIMARY KEY, name VARCHAR(10) UNIQUE)');
set_sql('insert1', 'INSERT INTO classtypes VALUES(0, \'stdClass\')');
set_sql('insert2', 'INSERT INTO classtypes VALUES(1, \'Test1\')');
set_sql('insert3', 'INSERT INTO classtypes VALUES(2, \'Test2\')');
set_sql('create2', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10))');
set_sql('insert4', 'INSERT INTO test VALUES(1, 0, \'A\')');
set_sql('insert5', 'INSERT INTO test VALUES(2, 1, \'B\')');
set_sql('insert6', 'INSERT INTO test VALUES(3, 2, \'C\')');
set_sql('insert7', 'INSERT INTO test VALUES(4, 3, \'D\')');
set_sql('select', 'SELECT classtypes.name, test.id AS id, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id');
$DB->exec($SQL['create1']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$DB->exec($SQL['create2']);
$DB->exec($SQL['insert4']);
$DB->exec($SQL['insert5']);
$DB->exec($SQL['insert6']);
$DB->exec($SQL['insert7']);
class Test1
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test2
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test3
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_NUM));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE, 'Test3'));
?>

View File

@ -1,53 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE classtypes(id int NOT NULL PRIMARY KEY, name VARCHAR(10) UNIQUE)');
set_sql('insert1', 'INSERT INTO classtypes VALUES(0, \'stdClass\')');
set_sql('insert2', 'INSERT INTO classtypes VALUES(1, \'Test1\')');
set_sql('insert3', 'INSERT INTO classtypes VALUES(2, \'Test2\')');
set_sql('create2', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(10), grp VARCHAR(10))');
set_sql('insert4', 'INSERT INTO test VALUES(1, 0, \'A\', \'Group1\')');
set_sql('insert5', 'INSERT INTO test VALUES(2, 1, \'B\', \'Group1\')');
set_sql('insert6', 'INSERT INTO test VALUES(3, 2, \'C\', \'Group2\')');
set_sql('insert7', 'INSERT INTO test VALUES(4, 3, \'D\', \'Group2\')');
set_sql('select', 'SELECT classtypes.name, test.grp AS grp, test.id AS id, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id');
$DB->exec($SQL['create1']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$DB->exec($SQL['create2']);
$DB->exec($SQL['insert4']);
$DB->exec($SQL['insert5']);
$DB->exec($SQL['insert6']);
$DB->exec($SQL['insert7']);
class Test1
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test2
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
class Test3
{
public function __construct()
{
echo __METHOD__ . "()\n";
}
}
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE|PDO_FETCH_GROUP, 'Test3'));
var_dump($DB->query($SQL['select'])->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE|PDO_FETCH_UNIQUE, 'Test3'));
?>

View File

@ -1,67 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL 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\', \'Group1\')');
set_sql('insert3', 'INSERT INTO test VALUES(3, \'C\', \'Group2\')');
set_sql('insert4', 'INSERT INTO test VALUES(4, \'D\', \'Group2\')');
set_sql('select1', 'SELECT grp, id FROM test');
set_sql('select2', 'SELECT id, val FROM test');
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
$DB->exec($SQL['insert4']);
class Test1
{
public function __construct($id, $val)
{
echo __METHOD__ . "($id,$val)\n";
$this->id = $id;
$this->val = $val;
}
static public function factory($id, $val)
{
echo __METHOD__ . "($id,$val)\n";
return new self($id, $val);
}
}
function test($id,$val='N/A')
{
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
}
$f = new Test1(0,0);
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_FUNC|PDO_FETCH_GROUP, 'test'));
var_dump($DB->query($SQL['select2'])->fetchAll(PDO_FETCH_FUNC, 'test'));
var_dump($DB->query($SQL['select2'])->fetchAll(PDO_FETCH_FUNC, array('Test1','factory')));
var_dump($DB->query($SQL['select2'])->fetchAll(PDO_FETCH_FUNC, array($f, 'factory')));
class DerivedStatement extends PDOStatement
{
private function __construct($name, $db)
{
$this->name = $name;
echo __METHOD__ . "($name)\n";
}
function retrieve($id, $val) {
echo __METHOD__ . "($id,$val)\n";
return array($id=>$val);
}
}
$stmt = $DB->prepare($SQL['select2'], array(PDO_ATTR_STATEMENT_CLASS=>array('DerivedStatement', array('Overloaded', $DB))));
var_dump(get_class($stmt));
$stmt->execute();
var_dump($stmt->fetchAll(PDO_FETCH_FUNC, array($stmt, 'retrieve')));
?>

View File

@ -1,32 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL 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());
?>

View File

@ -1,39 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL 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);
}
?>

View File

@ -1,61 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id int NOT NULL 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);
}
?>

View File

@ -1,25 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(20))');
set_sql('insert1', 'INSERT INTO test VALUES(1, \'A\', \'A2\')');
set_sql('insert2', 'INSERT INTO test VALUES(2, \'A\', \'B2\')');
set_sql('select1', 'SELECT id, val, val2 FROM test');
set_sql('select2', 'SELECT val, val2 FROM test');
$DB->exec($SQL['create1']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN));
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN, 2));
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_GROUP));
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE));
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE, 0));
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE, 1));
var_dump($DB->query($SQL['select1'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE, 2));
var_dump($DB->query($SQL['select2'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_GROUP));
?>

View File

@ -1,82 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))');
set_sql('insert1', 'INSERT INTO test VALUES(0, \'String0\')');
set_sql('insert2', 'INSERT INTO test VALUES(1, \'String1\')');
set_sql('insert3', 'INSERT INTO test VALUES(2, \'String2\')');
set_sql('select1', 'SELECT COUNT(*) FROM test');
set_sql('select2', 'SELECT idx, txt FROM test ORDER by idx');
set_sql('select3', 'SELECT txt FROM test WHERE idx=:inp');
set_sql('select4', 'SELECT idx FROM test WHERE txt=:txt');
echo "===INIT===\n";
$DB->exec($SQL['create1']);
var_dump($DB->exec($SQL['insert1']));
var_dump($DB->exec($SQL['insert2']));
var_dump($DB->exec($SQL['insert3']));
var_dump($DB->query($SQL['select1'])->fetchColumn());
$cont = $DB->query($SQL['select2'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE);
var_dump($cont);
echo "===WHILE===\n";
$stmt2 = $DB->prepare($SQL['select2']);
$stmt2->bindColumn('idx', $idx);
$stmt2->bindColumn('txt', $txt);
$stmt2->execute();
while($stmt2->fetch(PDO_FETCH_BOUND)) {
var_dump(array($idx=>$txt));
}
echo "===ALONE===\n";
$stmt3 = $DB->prepare($SQL['select3']);
$stmt3->bindParam(':inp', $idx); /* by foreign name */
$stmt3->bindColumn('txt', $col1);
$stmt4 = $DB->prepare($SQL['select4']);
$stmt4->bindParam(':txt', $txt); /* using same name */
$stmt4->bindColumn('idx', $col2);
foreach($cont as $idx => $txt)
{
var_dump(array($idx=>$txt));
var_dump($stmt3->execute());
var_dump($stmt3->fetch(PDO_FETCH_BOUND));
var_dump($stmt4->execute());
var_dump($stmt4->fetch(PDO_FETCH_BOUND));
var_dump(array($col2=>$col1));
}
echo "===REBIND/SAME===\n";
$stmt4->bindColumn('idx', $col1);
foreach($cont as $idx => $txt)
{
var_dump(array($idx=>$txt));
var_dump($stmt3->execute());
var_dump($stmt3->fetch(PDO_FETCH_BOUND));
var_dump($col1);
var_dump($stmt4->execute());
var_dump($stmt4->fetch(PDO_FETCH_BOUND));
var_dump($col1);
}
echo "===REBIND/CONFLICT===\n";
$stmt2->bindColumn('idx', $col1);
$stmt2->bindColumn('txt', $col1);
$stmt2->execute();
while($stmt2->fetch(PDO_FETCH_BOUND))
{
var_dump($col1);
}
?>

View File

@ -1,32 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', "INSERT INTO test VALUES(1, 'A')");
set_sql('insert2', "INSERT INTO test VALUES(2, 'B')");
set_sql('insert3', "INSERT INTO test VALUES(3, 'C')");
set_sql('select', 'SELECT COUNT(*) FROM test');
set_sql('delete', 'DELETE FROM test');
function countRows($DB, $action) {
global $SQL;
$stmt = $DB->query($SQL['select']);
$res = $stmt->fetchColumn();
return "Counted $res rows after $action.\n";
}
$DB->exec($SQL['create']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
echo countRows($DB, 'insert');
$DB->beginTransaction();
$DB->exec($SQL['delete']);
echo countRows($DB, 'delete');
$DB->rollBack();
echo countRows($DB, 'rollback');
?>

View File

@ -1,149 +0,0 @@
<?php # vim:ft=php
class TestBase implements Serializable
{
public $BasePub = 'Public';
protected $BasePro = 'Protected';
private $BasePri = 'Private';
function serialize()
{
$serialized = array();
foreach($this as $prop => $val) {
$serialized[$prop] = $val;
}
$serialized = serialize($serialized);
echo __METHOD__ . "() = '$serialized'\n";
return $serialized;
}
function unserialize($serialized)
{
echo __METHOD__ . '[' . __LINE__ . ']' . "($serialized)\n";
foreach(unserialize($serialized) as $prop => $val) {
$this->$prop = '#'.$val;
}
return true;
}
}
class TestDerived extends TestBase
{
public $BasePub = 'DerivedPublic';
protected $BasePro = 'DerivdeProtected';
public $DerivedPub = 'Public';
protected $DerivedPro = 'Protected';
private $DerivedPri = 'Private';
function serialize()
{
echo __METHOD__ . "()\n";
return TestBase::serialize();
}
function unserialize($serialized)
{
echo __METHOD__ . "()\n";
return TestBase::unserialize($serialized);
}
}
class TestLeaf extends TestDerived
{
}
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE classtypes(id int NOT NULL PRIMARY KEY, name VARCHAR(20) UNIQUE)');
set_sql('insert1', 'INSERT INTO classtypes VALUES(0, \'stdClass\')');
set_sql('insert2', 'INSERT INTO classtypes VALUES(1, \'TestBase\')');
set_sql('insert3', 'INSERT INTO classtypes VALUES(2, \'TestDerived\')');
set_sql('selectC', 'SELECT COUNT(*) FROM classtypes');
set_sql('select0', 'SELECT id, name FROM classtypes ORDER by id');
set_sql('create2', 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(255))');
set_sql('insert4', 'INSERT INTO test VALUES(:id, :classtype, :val)');
set_sql('select1', 'SELECT id FROM classtypes WHERE name=:cname');
set_sql('select2', 'SELECT test.val FROM test');
set_sql('select3', 'SELECT classtypes.name AS name, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id');
set_sql('select4', 'SELECT COUNT(*) FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id WHERE (classtypes.id IS NULL OR classtypes.id > 0)');
set_sql('select5', 'SELECT classtypes.name AS name, test.val AS val FROM test LEFT JOIN classtypes ON test.classtype=classtypes.id WHERE (classtypes.id IS NULL OR classtypes.id > 0)');
$DB->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
echo "===INIT===\n";
$DB->exec($SQL['create1']);
var_dump($DB->exec($SQL['insert1']));
var_dump($DB->exec($SQL['insert2']));
var_dump($DB->exec($SQL['insert3']));
$DB->exec($SQL['create2']);
var_dump($DB->query($SQL['selectC'])->fetchColumn());
var_dump($DB->query($SQL['select0'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE));
$objs = array();
$objs[0] = new stdClass;
$objs[1] = new TestBase;
$objs[2] = new TestDerived;
$objs[3] = new TestLeaf;
$stmt = $DB->prepare($SQL['select1']);
$stmt->bindParam(':cname', $cname);
$stmt->bindColumn('id', $ctype);
$ctypes = array();
foreach($objs as $obj)
{
$cname = get_class($obj);
$ctype = NULL; /* set default for non stored class name */
$stmt->execute();
$stmt->fetch(PDO_FETCH_BOUND);
$ctypes[$cname] = $ctype;
}
echo "===TYPES===\n";
var_dump($ctypes);
echo "===INSERT===\n";
$stmt = $DB->prepare($SQL['insert4']);
$stmt->bindParam(':id', $idx);
$stmt->bindParam(':classtype', $ctype);
$stmt->bindParam(':val', $val);
foreach($objs as $idx => $obj)
{
$ctype = $ctypes[get_class($obj)];
if (method_exists($obj, 'serialize'))
{
$val = $obj->serialize();
}
else
{
$val = NULL;
}
$stmt->execute();
}
echo "===DATA===\n";
var_dump($DB->query($SQL['select2'])->fetchAll(PDO_FETCH_COLUMN));
echo "===FAILURE===\n";
try
{
$DB->query($SQL['select3'])->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE|PDO_FETCH_SERIALIZE, 'TestLeaf', array());
}
catch (PDOException $e)
{
echo 'Exception:';
echo $e->getMessage()."\n";
}
echo "===COUNT===\n";
var_dump($DB->query($SQL['select4'])->fetchColumn());
echo "===DATABASE===\n";
var_dump($DB->query($SQL['select5'])->fetchAll(PDO_FETCH_ASSOC));
echo "===FETCHCLASS===\n";
var_dump($DB->query($SQL['select5'])->fetchAll(PDO_FETCH_CLASS|PDO_FETCH_CLASSTYPE|PDO_FETCH_SERIALIZE, 'TestLeaf'));
?>

View File

@ -1,36 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))');
set_sql('insert1', 'INSERT INTO test VALUES(0, \'String0\')');
set_sql('insert2', 'INSERT INTO test VALUES(1, \'String1\')');
set_sql('insert3', 'INSERT INTO test VALUES(2, \'String2\')');
set_sql('insert4', 'INSERT INTO test VALUES(3, \'String3\')');
set_sql('select1', 'SELECT COUNT(*) FROM test');
set_sql('select2', 'SELECT idx, txt FROM test ORDER by idx');
echo "===INIT===\n";
$DB->exec($SQL['create1']);
var_dump($DB->exec($SQL['insert1']));
var_dump($DB->exec($SQL['insert2']));
var_dump($DB->exec($SQL['insert3']));
var_dump($DB->exec($SQL['insert4']));
var_dump($DB->query($SQL['select1'])->fetchColumn());
$cont = $DB->query($SQL['select2'])->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE);
var_dump($cont);
echo "===WHILE===\n";
$stmt2 = $DB->prepare($SQL['select2']);
$stmt2->bindColumn('idx', $idx);
$stmt2->bindColumn('txt', $txt);
$stmt2->execute();
while($stmt2->fetch(PDO_FETCH_BOUND)) {
var_dump(array($idx=>$txt));
}
?>

View File

@ -1,28 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
set_sql('insert1', "INSERT INTO test VALUES(1, 'A', 'A')");
set_sql('insert2', "INSERT INTO test VALUES(2, 'B', 'B')");
set_sql('insert3', "INSERT INTO test VALUES(3, 'C', 'C')");
set_sql('select1', 'SELECT id, val FROM test');
set_sql('select2', 'SELECT id, val, val2 FROM test');
set_sql('select3', 'SELECT COUNT(*) FROM test');
function countColumns($DB, $action) {
global $SQL;
$stmt = $DB->query($SQL[$action]);
$res = $stmt->columnCount();
return "Counted $res columns after $action.\n";
}
$DB->exec($SQL['create1']);
$DB->exec($SQL['insert1']);
$DB->exec($SQL['insert2']);
$DB->exec($SQL['insert3']);
echo countColumns($DB, 'select1');
echo countColumns($DB, 'select2');
echo countColumns($DB, 'select3');
?>

View File

@ -1,42 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
set_sql('insert1', "INSERT INTO test VALUES(?, ?, ?)");
set_sql('insert2', "INSERT INTO test VALUES(:first, :second, :third)");
set_sql('select', 'SELECT COUNT(*) FROM test');
$data = array(
array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'),
);
$DB->exec($SQL['create1']);
// Insert using question mark placeholders
$stmt = $DB->prepare($SQL['insert1']);
foreach ($data as $row) {
$stmt->execute($row);
}
$select = $DB->query($SQL['select']);
$num = $select->fetchColumn();
echo 'There are ' . $num . " rows in the table.\n";
// Insert using named parameters
$stmt2 = $DB->prepare($SQL['insert2']);
foreach ($data as $row) {
$stmt2->execute(array(':first'=>($row[0] + 5), ':second'=>$row[1],
':third'=>$row[2]));
}
$select = $DB->query($SQL['select']);
$num = $select->fetchColumn();
echo 'There are ' . $num . " rows in the table.\n";
?>

View File

@ -1,41 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
set_sql('insert1', "INSERT INTO test VALUES(?, ?, ?)");
set_sql('insert2', "INSERT INTO test VALUES(:first, :second, :third)");
set_sql('select1', 'SELECT id, val, val2 FROM test');
set_sql('select2', 'SELECT COUNT(*) FROM test');
$data = array(
array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'),
);
$DB->exec($SQL['create1']);
// Insert using question mark placeholders
$stmt = $DB->prepare($SQL['insert1']);
foreach ($data as $row) {
$stmt->execute($row);
}
// Retrieve column metadata for a result set returned by explicit SELECT
$select = $DB->query($SQL['select1']);
$meta = $select->getColumnMeta(0);
var_dump($meta);
$meta = $select->getColumnMeta(1);
var_dump($meta);
$meta = $select->getColumnMeta(2);
var_dump($meta);
// Retrieve column metadata for a result set returned by a function
$select = $DB->query($SQL['select2']);
$meta = $select->getColumnMeta(0);
var_dump($meta);
?>

View File

@ -1,26 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))');
set_sql('insert1', 'INSERT INTO test VALUES(0, \'A\')');
set_sql('insert2', 'INSERT INTO test VALUES(1, \'B\')');
set_sql('select1', 'SELECT val, id FROM test');
$DB->test();
var_dump($DB);
$DB->query($SQL['create1']);
$DB->query($SQL['insert1']);
$DB->query($SQL['insert2']);
$stmt = $DB->query($SQL['select1']);
var_dump($stmt);
var_dump($stmt->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE));
$stmt = NULL;
$DB = NULL;
?>

View File

@ -1,46 +0,0 @@
<?php
class PDOStatementX extends PDOStatement
{
public $test1 = 1;
protected function __construct()
{
$this->test2 = 2;
$this->test2 = 22;
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
}
class PDODatabaseX extends PDO
{
public $test1 = 1;
function __destruct()
{
echo __METHOD__ . "()\n";
}
function test()
{
$this->test2 = 2;
var_dump($this->test1);
var_dump($this->test2);
$this->test2 = 22;
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = parent::prepare($sql, array(PDO_ATTR_STATEMENT_CLASS=>array('PDOStatementx')));
$stmt->execute();
return $stmt;
}
}
?>

View File

@ -1,21 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create', 'create table test (id int, name varchar(10))');
set_sql('insert', 'insert into test (id, name) values(0, :name)');
set_sql('select', 'select name from test where id=0');
$DB->query($SQL['create']);
$stmt = $DB->prepare($SQL['insert']);
$name = NULL;
$before_bind = $name;
$stmt->bindParam(':name', $name);
if ($name !== $before_bind) {
echo "bind: fail\n";
} else {
echo "bind: success\n";
}
var_dump($stmt->execute());
var_dump($DB->query($SQL['select'])->fetchColumn());
?>

View File

@ -1,51 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
set_sql('insert1', "INSERT INTO test VALUES(?, ?, ?)");
set_sql('select', 'SELECT * FROM test');
$data = array(
array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
array('40', 'Jkl', 'qpo'),
array('50', 'Mno', 'nml'),
array('60', 'Pqr', 'kji'),
);
$DB->exec($SQL['create1']);
// Insert using question mark placeholders
$stmt = $DB->prepare($SQL['insert1']);
foreach ($data as $row) {
$stmt->execute($row);
}
class Test {
public $id, $val, $val2;
}
$stmt = $DB->prepare($SQL['select']);
$stmt->setFetchMode(PDO_FETCH_INTO, new Test);
$stmt->execute();
foreach($stmt as $obj) {
var_dump($obj);
}
echo "===FAIL===\n";
class Fail {
protected $id;
public $val, $val2;
}
$stmt->setFetchMode(PDO_FETCH_INTO, new Fail);
$stmt->execute();
foreach($stmt as $obj) {
var_dump($obj);
}
?>

View File

@ -1,69 +0,0 @@
<?php # vim:ft=php
require_once('pdo.inc');
set_sql('create1', 'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
set_sql('insert1', "INSERT INTO test VALUES(?, ?, ?)");
set_sql('select', 'SELECT * FROM test');
$data = array(
array('10', 'Abc', 'zxy'),
array('20', 'Def', 'wvu'),
array('30', 'Ghi', 'tsr'),
);
class PDOStatementX extends PDOStatement
{
public $dbh;
protected function __construct($dbh)
{
$this->dbh = $dbh;
echo __METHOD__ . "()\n";
}
function __destruct()
{
echo __METHOD__ . "()\n";
}
}
class PDODatabase extends PDO
{
function __destruct()
{
echo __METHOD__ . "()\n";
}
function query($sql)
{
echo __METHOD__ . "()\n";
$stmt = $this->prepare($sql, array(PDO_ATTR_STATEMENT_CLASS=>array('PDOStatementx', array($this))));
$stmt->setFetchMode(PDO_FETCH_ASSOC);
$stmt->execute();
return $stmt;
}
}
$DB = new PDODatabase($CONNECTION, isset($USER) ? $USER : NULL, isset($PASSWD) ? $PASSWD : NULL);
var_dump(get_class($DB));
$DB->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_WARNING);
$DB->exec($SQL['create1']);
$stmt = $DB->prepare($SQL['insert1']);
var_dump(get_class($stmt));
foreach ($data as $row) {
$stmt->execute($row);
}
$stmt = $DB->query($SQL['select']);
var_dump(get_class($stmt));
var_dump(get_class($stmt->dbh));
foreach($stmt as $obj) {
var_dump($obj);
}
?>