1st set of fixes to make tests work with MySQL

# Additional changes pending
This commit is contained in:
Ilia Alshanetsky 2005-07-07 18:49:58 +00:00
parent e7b930ea9a
commit 5156c7b38f
7 changed files with 32 additions and 1 deletions

View File

@ -30,9 +30,13 @@ class Test
}
}
unset($stmt);
$stmt = $db->query($SELECT, PDO_FETCH_CLASS, 'Test');
var_dump($stmt->fetchAll());
unset($stmt);
$stmt = $db->query($SELECT, PDO_FETCH_NUM);
$stmt->setFetchMode(PDO_FETCH_CLASS, 'Test', array('Changed'));
var_dump($stmt->fetchAll());

View File

@ -36,11 +36,15 @@ class Test
}
}
unset($stmt);
foreach ($db->query($SELECT, PDO_FETCH_CLASS, 'Test') as $data)
{
var_dump($data);
}
unset($stmt);
$stmt = $db->query($SELECT, PDO_FETCH_CLASS, 'Test', array('WOW'));
foreach($stmt as $data)

View File

@ -17,6 +17,11 @@ $db->exec('CREATE TABLE test(idx int NOT NULL PRIMARY KEY, txt VARCHAR(20))');
$db->exec('INSERT INTO test VALUES(0, \'String0\')');
$db->exec('INSERT INTO test VALUES(1, \'String1\')');
$db->exec('INSERT INTO test VALUES(2, \'String2\')');
if ($db->getAttribute(PDO_ATTR_DRIVER_NAME) == 'mysql') {
$db->setAttribute(PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
}
$stmt1 = $db->prepare('SELECT COUNT(idx) FROM test');
$stmt2 = $db->prepare('SELECT idx, txt FROM test ORDER by idx');

View File

@ -22,7 +22,13 @@ try {
require getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))');
if ($db->getAttribute(PDO_ATTR_DRIVER_NAME) == 'mysql') {
$suf = ' Type=InnoDB';
} else {
$suf = '';
}
$db->exec('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))'.$suf);
$db->exec("INSERT INTO test VALUES(1, 'A')");
$db->exec("INSERT INTO test VALUES(2, 'B')");
$db->exec("INSERT INTO test VALUES(3, 'C')");

View File

@ -77,6 +77,10 @@ $db->setAttribute(PDO_ATTR_ERRMODE, PDO_ERRMODE_EXCEPTION);
var_dump($db->query('SELECT COUNT(*) FROM classtypes')->fetchColumn());
var_dump($db->query('SELECT id, name FROM classtypes ORDER by id')->fetchAll(PDO_FETCH_COLUMN|PDO_FETCH_UNIQUE));
if ($db->getAttribute(PDO_ATTR_DRIVER_NAME) == 'mysql') {
$db->setAttribute(PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
}
$objs = array();
$objs[0] = new stdClass;
$objs[1] = new TestBase;
@ -101,6 +105,8 @@ foreach($objs as $obj)
echo "===TYPES===\n";
var_dump($ctypes);
unset($stmt);
echo "===INSERT===\n";
$stmt = $db->prepare('INSERT INTO test VALUES(:id, :classtype, :val)');
$stmt->bindParam(':id', $idx);
@ -121,6 +127,8 @@ foreach($objs as $idx => $obj)
$stmt->execute();
}
unset($stmt);
echo "===DATA===\n";
var_dump($db->query('SELECT test.val FROM test')->fetchAll(PDO_FETCH_COLUMN));

View File

@ -36,6 +36,8 @@ $select->execute();
$num = $select->fetchColumn();
echo 'There are ' . $num . " rows in the table.\n";
unset($stmt);
// Insert using named parameters
$stmt2 = $db->prepare("INSERT INTO test VALUES(:first, :second, :third)");
foreach ($data as $row) {

View File

@ -62,6 +62,8 @@ 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));