改进代码

This commit is contained in:
thinkphp
2016-05-17 18:19:13 +08:00
parent baebe7899e
commit 63521c1db3
3 changed files with 25 additions and 21 deletions

View File

@@ -506,13 +506,14 @@ abstract class Connection
*/
public function transaction($callback)
{
$this->startTrans(NOW_TIME);
$label = microtime(true);
$this->startTrans($label);
try {
$result = null;
if (is_callable($callback)) {
$result = call_user_func_array($callback, []);
}
$this->commit(NOW_TIME);
$this->commit($label);
return $result;
} catch (\PDOException $e) {
$this->rollback();