本文整理汇总了PHP中PDOTest::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP PDOTest::factory方法的具体用法?PHP PDOTest::factory怎么用?PHP PDOTest::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PDOTest
的用法示例。
在下文中一共展示了PDOTest::factory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putenv
<?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());
示例2: putenv
<?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));
示例3: __destruct
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";