public
Created

  • Download Gist
DBAL202.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
<?php
 
##
# http://www.doctrine-project.org/jira/browse/DBAL-202
# Scenario where PDO and DBAL behavior differ
#
# pdo: 0
# dbal: 1
##
 
require_once __DIR__ . '/tests/Doctrine/Tests/TestInit.php';
error_reporting(-1);
 
$ref = array(
'dbname' => null,
'dbuser' => null,
'dbpass' => null,
'setup' => 'CREATE TABLE TABLE1 ( COLUMN1 NUMBER )',
'cleanup' => 'DROP TABLE TABLE1',
'dml' => 'INSERT INTO TABLE1 VALUES ( :value )',
'test' => 'SELECT COUNT(1) FROM TABLE1',
);
 
 
// pdo
$dbh = new PDO('oci:dbname=' . $ref['dbname'], $ref['dbuser'], $ref['dbpass']);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->exec($ref['setup']);
 
$stmt = $dbh->prepare($ref['dml']);
$dbh->beginTransaction();
$stmt->execute(array('value' => 1234));
$dbh->rollBack();
 
fwrite(STDOUT, 'pdo: ' . $dbh->query($ref['test'])->fetchColumn() . "\n");
$dbh->exec($ref['cleanup']);
unset($stmt, $dbh);
 
 
// dbal
$dbh = \Doctrine\DBAL\DriverManager::getConnection(array('driver' => 'oci8',
'user' => $ref['dbuser'], 'password' => $ref['dbpass'], 'dbname' => $ref['dbname']
));
$dbh->executeQuery($ref['setup']);
 
$stmt = $dbh->prepare($ref['dml']);
$dbh->beginTransaction();
$stmt->execute(array('value' => 1234));
$dbh->rollback();
 
fwrite(STDOUT, 'dbal: ' . $dbh->query($ref['test'])->fetchColumn() . "\n");
$dbh->exec($ref['cleanup']);
unset($stmt, $dbh);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.