php-src/ext/pdo/tests/pdo_test.inc
Wez Furlong 007f571beb for the transactions test case, detect working transactions before attempting to run the tests.
Additional ugliness required because mysql does stupid stuff like this:

mysql> CREATE TABLE foo (id int) TYPE=innodb;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> SHOW CREATE TABLE foo;
CREATE TABLE `foo` (
  `id` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

In addition, BEGIN, COMMIT and ROLLBACK all succeed, even when no tables
support transactions.
2005-07-09 04:28:45 +00:00

60 lines
1.3 KiB
PHP

<?php
# PDO test framework utilities
class PDOTest {
// create an instance of the PDO driver, based on
// the current environment
static function factory($classname = 'PDO') {
$dsn = getenv('PDOTEST_DSN');
$user = getenv('PDOTEST_USER');
$pass = getenv('PDOTEST_PASS');
$attr = getenv('PDOTEST_ATTR');
if (is_string($attr) && strlen($attr)) {
$attr = unserialize($attr);
} else {
$attr = null;
}
if ($user === false) $user = NULL;
if ($pass === false) $pass = NULL;
$db = new $classname($dsn, $user, $pass, $attr);
// clean up any crufty test tables we might have left behind
// on a previous run
static $test_tables = array(
'test',
'classtypes'
);
foreach ($test_tables as $table) {
$db->exec("DROP TABLE $table");
}
$db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_WARNING);
$db->setAttribute(PDO_ATTR_CASE, PDO_CASE_LOWER);
$db->setAttribute(PDO_ATTR_STRINGIFY_FETCHES, true);
return $db;
}
static function skip() {
try {
$db = PDOTest::factory();
} catch (PDOException $e) {
die("skip " . $e->getMessage());
}
}
static function detect_transactional_mysql_engine($db) {
foreach ($db->query('show engines') as $row) {
if ($row[1] == 'YES' && ($row[0] == 'INNOBASE' || $row[0] == 'BDB')) {
return $row[0];
}
}
return false;
}
}
?>