mirror of
https://github.com/php/php-src.git
synced 2025-01-26 13:44:22 +08:00
be0793d2e7
pecl#12794, pecl#12401 # Running the tests: # (Note: Doesn't work currnetly on HEAD, see: # http://news.php.net/php.qa/64378) # # PDO_MYSQL_TEST_DSN - DSN # For example: mysql:dbname=test;host=localhost;port=3306 # # PDO_MYSQL_TEST_HOST - database host # PDO_MYSQL_TEST_DB - database (schema) name # PDO_MYSQL_TEST_SOCKET - database server socket # PDO_MYSQL_TEST_ENGINE - storage engine to use # PDO_MYSQL_TEST_USER - database user # PDO_MYSQL_TEST_PASS - database user password # PDO_MYSQL_TEST_CHARSET - database charset # # NOTE: if any of PDO_MYSQL_TEST_[HOST|DB|SOCKET|ENGINE|CHARSET] is # part of PDO_MYSQL_TEST_DSN, the values must match. That is, for example, # for PDO_MYSQL_TEST_DSN = mysql:dbname=test you MUST set PDO_MYSQL_TEST_DB=test.
93 lines
3.5 KiB
PHP
93 lines
3.5 KiB
PHP
--TEST--
|
|
PDO::ATTR_AUTOCOMMIT
|
|
--SKIPIF--
|
|
<?php
|
|
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
|
|
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
|
MySQLPDOTest::skip();
|
|
$db = MySQLPDOTest::factory();
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
|
|
$db = MySQLPDOTest::factory();
|
|
|
|
// autocommit should be on by default
|
|
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
|
printf("[001] Expecting int/1 got %s\n", var_export($tmp, true));
|
|
|
|
// lets see if the server agrees to that
|
|
$row = $db->query('SELECT @@autocommit AS _autocommit')->fetch(PDO::FETCH_ASSOC);
|
|
if (!$row['_autocommit'])
|
|
printf("[002] Server autocommit mode should be on, got '%s'\n", var_export($row['_autocommit']));
|
|
|
|
// on -> off
|
|
if (!$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 0))
|
|
printf("[003] Cannot turn off autocommit\n");
|
|
|
|
$row = $db->query('SELECT @@autocommit AS _autocommit')->fetch(PDO::FETCH_ASSOC);
|
|
if ($row['_autocommit'])
|
|
printf("[004] Server autocommit mode should be off, got '%s'\n", var_export($row['_autocommit']));
|
|
|
|
// PDO thinks autocommit is off, but its manually turned on...
|
|
if (!$db->query('SET autocommit = 1'))
|
|
printf("[005] Cannot turn on server autocommit mode, %s\n", var_export($db->errorInfo(), true));
|
|
|
|
if (0 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
|
printf("[006] Expecting int/0 got %s\n", var_export($tmp, true));
|
|
|
|
// off -> on
|
|
if (!$db->query('SET autocommit = 0'))
|
|
printf("[007] Cannot turn off server autocommit mode, %s\n", var_export($db->errorInfo(), true));
|
|
|
|
if (!$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 1))
|
|
printf("[008] Cannot turn on autocommit\n");
|
|
|
|
$row = $db->query('SELECT @@autocommit AS _autocommit')->fetch(PDO::FETCH_ASSOC);
|
|
if (!$row['_autocommit'])
|
|
printf("[009] Server autocommit mode should be on, got '%s'\n", var_export($row['_autocommit']));
|
|
|
|
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
|
|
printf("[010] Expecting int/1 got %s\n", var_export($tmp, true));
|
|
|
|
if (MySQLPDOTest::detect_transactional_mysql_engine($db)) {
|
|
// nice, we have a transactional engine to play with
|
|
|
|
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
|
|
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
|
$num = $row['_num'];
|
|
|
|
$db->query('INSERT INTO test(id, label) VALUES (100, "z")');
|
|
$num++;
|
|
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
|
if ($row['_num'] != $num)
|
|
printf("[011] Insert has failed, test will fail\n");
|
|
|
|
// autocommit is on, no rollback possible
|
|
$db->query('ROLLBACK');
|
|
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
|
if ($row['_num'] != $num)
|
|
printf("[012] ROLLBACK should not have undone anything\n");
|
|
|
|
if (!$db->setAttribute(PDO::ATTR_AUTOCOMMIT, 0))
|
|
printf("[013] Cannot turn off autocommit\n");
|
|
|
|
$db->query('DELETE FROM test WHERE id = 100');
|
|
$db->query('ROLLBACK');
|
|
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
|
if ($row['_num'] != $num)
|
|
printf("[014] ROLLBACK should have undone the DELETE\n");
|
|
|
|
$db->query('DELETE FROM test WHERE id = 100');
|
|
$db->query('COMMIT');
|
|
$num--;
|
|
$row = $db->query('SELECT COUNT(*) AS _num FROM test')->fetch(PDO::FETCH_ASSOC);
|
|
if ($row['_num'] != $num)
|
|
printf("[015] DELETE should have been committed\n");
|
|
|
|
}
|
|
|
|
$db->exec(sprintf('DROP TABLE IF EXISTS test'));
|
|
print "done!";
|
|
--EXPECTF--
|
|
done!
|