|
@@ -16,8 +16,6 @@ class Db
|
|
const ErrUnConnect = 2006;
|
|
const ErrUnConnect = 2006;
|
|
const ErrLock = 1205;
|
|
const ErrLock = 1205;
|
|
|
|
|
|
- private static $ifTransacting = false;
|
|
|
|
-
|
|
|
|
private function __construct()
|
|
private function __construct()
|
|
{
|
|
{
|
|
if (!extension_loaded('mysqli')) {
|
|
if (!extension_loaded('mysqli')) {
|
|
@@ -111,8 +109,7 @@ class Db
|
|
|
|
|
|
public static function ping($host = 'master')
|
|
public static function ping($host = 'master')
|
|
{
|
|
{
|
|
- $cid = Co::getCid();
|
|
|
|
- $link = CoMysqliPool::instance()->find($cid);
|
|
|
|
|
|
+ $link = CoMysqliPool::instance()->find(Co::getCid());
|
|
|
|
|
|
if (is_object($link[$host])) {
|
|
if (is_object($link[$host])) {
|
|
return $link[$host]->ping();
|
|
return $link[$host]->ping();
|
|
@@ -145,7 +142,7 @@ class Db
|
|
if ($eno == self::ErrUnConnect) {
|
|
if ($eno == self::ErrUnConnect) {
|
|
if ($count > 0) return false;
|
|
if ($count > 0) return false;
|
|
$link = self::connect($link,$host);
|
|
$link = self::connect($link,$host);
|
|
- CoMysqliPool::instance()->reset($cid,$link);
|
|
|
|
|
|
+ CoMysqliPool::instance()->reset(Co::getCid(),$link);
|
|
$count++;
|
|
$count++;
|
|
} elseif (C('debug')) {
|
|
} elseif (C('debug')) {
|
|
throw_exception($error . '<br/>' . $sql);
|
|
throw_exception($error . '<br/>' . $sql);
|
|
@@ -155,7 +152,7 @@ class Db
|
|
{
|
|
{
|
|
if ($count > 0) return false;
|
|
if ($count > 0) return false;
|
|
$link = self::connect($link,$host);
|
|
$link = self::connect($link,$host);
|
|
- CoMysqliPool::instance()->reset($cid,$link);
|
|
|
|
|
|
+ CoMysqliPool::instance()->reset(Co::getCid(),$link);
|
|
$count++;
|
|
$count++;
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -632,11 +629,10 @@ class Db
|
|
$result = $link[$host]->autocommit(false);
|
|
$result = $link[$host]->autocommit(false);
|
|
if ($result == false) {
|
|
if ($result == false) {
|
|
$link = self::connect($host);
|
|
$link = self::connect($host);
|
|
- CoMysqliPool::instance()->reset($cid,$link);
|
|
|
|
- Log::record("autocommit start 2", Log::DEBUG);
|
|
|
|
|
|
+ CoMysqliPool::instance()->reset(Co::getCid(),$link);
|
|
$link[$host]->autocommit(false);
|
|
$link[$host]->autocommit(false);
|
|
} else {
|
|
} else {
|
|
- Log::record("autocommit start 1", Log::DEBUG);
|
|
|
|
|
|
+ Log::record("autocommit fail", Log::DEBUG);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
CoMysqliPool::instance()->begin(Co::getCid());
|
|
CoMysqliPool::instance()->begin(Co::getCid());
|
|
@@ -649,7 +645,6 @@ class Db
|
|
if ($ifTransacting)
|
|
if ($ifTransacting)
|
|
{
|
|
{
|
|
$result = $link[$host]->commit();
|
|
$result = $link[$host]->commit();
|
|
- Log::record("autocommit end commit", Log::DEBUG);
|
|
|
|
$link[$host]->autocommit(true);
|
|
$link[$host]->autocommit(true);
|
|
CoMysqliPool::instance()->commit(Co::getCid());
|
|
CoMysqliPool::instance()->commit(Co::getCid());
|
|
|
|
|
|
@@ -669,8 +664,6 @@ class Db
|
|
{
|
|
{
|
|
$result = $link[$host]->rollback();
|
|
$result = $link[$host]->rollback();
|
|
CoMysqliPool::instance()->rollback(Co::getCid());
|
|
CoMysqliPool::instance()->rollback(Co::getCid());
|
|
-
|
|
|
|
- Log::record("autocommit end rollback", Log::DEBUG);
|
|
|
|
$fsuccess = $link[$host]->autocommit(true);
|
|
$fsuccess = $link[$host]->autocommit(true);
|
|
|
|
|
|
if (!$result || !$fsuccess) {
|
|
if (!$result || !$fsuccess) {
|