mirror of
https://github.com/php/php-src.git
synced 2024-11-29 04:46:07 +08:00
1st set of fixes to make tests work with MySQL
# Additional changes pending
This commit is contained in:
parent
e7b930ea9a
commit
5156c7b38f
@ -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());
|
||||
|
@ -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)
|
||||
|
@ -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');
|
||||
|
||||
|
@ -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')");
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user