$c1 = [
'type' => 'mysql',
'hostname' => 'localhost',
'database' => 'diandan',
'username' => 'root',
'password' => 'bingo',
'charset' => 'utf8',
'prefix' => '',
];
$c2 = [
'type' => 'mysql',
'hostname' => 'localhost',
'database' => 'mz',
'username' => 'root',
'password' => 'bingo',
'charset' => 'utf8',
'prefix' => '',
];
$clinet1 = Db::connect($c1);
$clinet2 = Db::connect($c2);
$clinet1->startTrans();
$clinet2->startTrans();
try {
$clinet1->table('test_')->insert(['id' => 1]);
$clinet2->table('test_')->insert(['id' => 2]);
$clinet1->commit();
$clinet2->commit();
} catch (\Exception $e) {
// 回滚事务
$clinet1->rollback();
$clinet2->rollback();
echo $e->getMessage();
}
CREATE TABLE `test_`( `id` INT(1) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=INNODB CHARSET=utf8 COLLATE=utf8_general_ci;