本文整理汇总了PHP中MySQLPDOTest::detect_transactional_mysql_engine方法的典型用法代码示例。如果您正苦于以下问题:PHP MySQLPDOTest::detect_transactional_mysql_engine方法的具体用法?PHP MySQLPDOTest::detect_transactional_mysql_engine怎么用?PHP MySQLPDOTest::detect_transactional_mysql_engine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySQLPDOTest
的用法示例。
在下文中一共展示了MySQLPDOTest::detect_transactional_mysql_engine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dirname
<?php
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
try {
if (true !== ($tmp = $db->beginTransaction())) {
printf("[001] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
}
// DDL will issue an implicit commit
$db->exec(sprintf('DROP TABLE IF EXISTS test_commit'));
$db->exec(sprintf('CREATE TABLE test_commit(id INT) ENGINE=%s', MySQLPDOTest::detect_transactional_mysql_engine($db)));
if (true !== ($tmp = $db->commit())) {
printf("[002] No commit allowed? [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
}
// pdo_transaction_transitions should check this as well...
// ... just to be sure the most basic stuff really works we check it again...
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT))) {
printf("[003] According to the manual we should be back to autocommit mode, got %s/%s\n", gettype($tmp), var_export($tmp, true));
}
if (true !== ($tmp = $db->beginTransaction())) {
printf("[004] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
}
$db->exec("INSERT INTO test(id, label) VALUES (100, 'z')");
if (true !== ($tmp = $db->commit())) {
printf("[005] No commit allowed? [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
}
// a weak test without unicode etc. - lets leave that to dedicated tests
$stmt = $db->query('SELECT id, label FROM test WHERE id = 100');
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (!isset($rows[0]['label']) || $rows[0]['label'] != 'z') {
示例2: dirname
<?php
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
$db = MySQLPDOTest::factory();
MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
function find_invalid_int($valid_options)
{
do {
$invalid = mt_rand(-10000, 10000);
} while (in_array($invalid, $valid_options));
return $invalid;
}
function set_and_get($offset, $db, $attribute, $value)
{
$value_type = gettype($value);
try {
if (!$db->setAttribute($attribute, $value)) {
printf("[%03d] Cannot set attribute '%s' to value '%s'\n", $offset, $attribute, var_export($tmp, true));
return false;
}
if (gettype($value) != $value_type) {
printf("[%03d] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from %s to %s, test will not work properly\n", $offset, $value_type, gettype($value));
return false;
}
$tmp = $db->getAttribute($attribute);
if ($tmp !== $value) {
printf("[%03d] Attribute '%s' was set to '%s'/%s but getAttribute() reports '%s'/%s\n", $offset, $attribute, var_export($value, true), gettype($value), var_export($tmp, true), gettype($tmp));
return false;
}
} catch (PDOException $e) {
printf("[%03d] %s, [%s] %s\n", $offset, $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo()));
示例3: putenv
<?php
if (getenv('REDIR_TEST_DIR') === false) {
putenv('REDIR_TEST_DIR=' . dirname(__FILE__) . '/../../pdo/tests/');
}
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
$suf = ' ENGINE=' . MySQLPDOTest::detect_transactional_mysql_engine($db);
} 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')");
$delete = $db->prepare('DELETE FROM test');
function countRows($action)
{
global $db;
$select = $db->prepare('SELECT COUNT(*) FROM test');
$select->execute();
$res = $select->fetchColumn();
return "Counted {$res} rows after {$action}.\n";
}
echo countRows('insert');
$db->beginTransaction();
$delete->execute();
echo countRows('delete');
$db->rollBack();