示例#1
0
<?php

require dirname(__FILE__) . '/config.inc';
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8");
$db->exec('CREATE TABLE test(floatval DECIMAL(8,6))');
$db->exec('INSERT INTO test VALUES(2.34)');
$value = 4.56;
$stmt = $db->prepare('INSERT INTO test VALUES(?)');
$stmt->execute(array($value));
var_dump($db->query('SELECT * from test')->fetchAll(PDO::FETCH_ASSOC));
示例#2
0
文件: pdo_015.php 项目: badlamer/hhvm
<?php

if (getenv('REDIR_TEST_DIR') === false) {
    putenv('REDIR_TEST_DIR=' . dirname(__FILE__) . '/../../pdo/tests/');
}
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(20))');
$db->exec('INSERT INTO test VALUES(1, \'A\', \'A2\')');
$db->exec('INSERT INTO test VALUES(2, \'A\', \'B2\')');
$select1 = $db->prepare('SELECT id, val, val2 FROM test');
$select2 = $db->prepare('SELECT val, val2 FROM test');
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN));
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN, 2));
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP));
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE));
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0));
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 1));
$select1->execute();
var_dump($select1->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 2));
$select2->execute();
var_dump($select2->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_GROUP));
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 = PDOTest::factory('PDODatabase');
var_dump(get_class($db));
$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(16))');
$stmt = $db->prepare("INSERT INTO test VALUES(?, ?, ?)");
var_dump(get_class($stmt));
foreach ($data as $row) {
    $stmt->execute($row);
}
unset($stmt);
$stmt = $db->query('SELECT * FROM test');
var_dump(get_class($stmt));
var_dump(get_class($stmt->dbh));
foreach ($stmt as $obj) {
    var_dump($obj);
}
echo "===DONE===\n";
<?php

if (getenv('REDIR_TEST_DIR') === false) {
    putenv('REDIR_TEST_DIR=' . dirname(__FILE__) . '/../../pdo/tests/');
}
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$pdo = PDOTest::factory();
$pdo->exec("create table test (id integer primary key, n varchar(255))");
$pdo->exec("INSERT INTO test (id, n) VALUES (1, 'hi')");
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_CLASS);
$stmt = $pdo->prepare("SELECT * FROM test");
$stmt->execute();
var_dump($stmt->fetchAll());
if ($pdo->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
    $type = "clob";
} else {
    if ($pdo->getAttribute(PDO::ATTR_DRIVER_NAME) == 'firebird') {
        $type = 'BLOB SUB_TYPE TEXT';
    } else {
        $type = "text";
    }
}
$pdo->exec("create table test2 (id integer primary key, n {$type})");
$pdo->exec("INSERT INTO test2 (id, n) VALUES (1,'hi')");
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_FUNC);
$stmt = $pdo->prepare("SELECT * FROM test2");
$stmt->execute();
var_dump($stmt->fetchAll());
示例#5
0
            $this->outletSession->save($user);
        }
        $this->outletSession->flush(false);
        $this->outletSession->setAutoFlush(true);
    }
    protected function selectRecords($times)
    {
        // TODO: should we clear identity map after querying?
        for ($i = 0; $i < $times; $i++) {
            $this->outletSession->from('User')->find();
        }
    }
}
class User
{
    public $id;
    public $name;
    public function __construct($id = 0, $name = '')
    {
        $this->id = $id;
        $this->name = $name;
    }
}
include_once 'profiler.inc';
$prof = new Profiler(true, true, 'text');
//$prof = new Profiler(true, true, 'html', dirname(__FILE__).'/');
$runner = new PDOTest();
//$runner = new OutletTest();
$runner->setProfiler($prof);
$runner->run(1000);
$prof->printTimers(true);