当前位置: 首页>>代码示例>>PHP>>正文


PHP PDOTest::factory方法代码示例

本文整理汇总了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());
开发者ID:gleamingthecube,项目名称:php,代码行数:28,代码来源:ext_pdo_tests_bug_38253.php

示例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));
开发者ID:badlamer,项目名称:hhvm,代码行数:28,代码来源:pdo_015.php

示例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";
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:ext_pdo_tests_pdo_026.php


注:本文中的PDOTest::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。