Commit 16949fb7 authored by cuiweifeng's avatar cuiweifeng

update : mysql add configindex

parent 68a14dcd
......@@ -129,7 +129,7 @@ abstract class MysqlBase
if (in_array($method, self::$writeFuncitonList)) {
// 写操作
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
if (strpos($method, 'Master') !== false) {
$method = substr_replace($method, '', -6);
}
......@@ -137,7 +137,7 @@ abstract class MysqlBase
} elseif (in_array($method, self::$readFunctionList)) {
// 读操作
$type = static::READ;
self::$dbConnect[$type] = self::getConnection($type);
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
array_unshift($arguments, static::TABLE_NAME);
} elseif (strpos($method, 'query') !== false) {
// Medoo原生SQL操作
......@@ -146,17 +146,17 @@ abstract class MysqlBase
$type = static::WRITE;
}
$method = 'query';
self::$dbConnect[$type] = self::getConnection($type);
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
} else {
throw new \Exception("use undefined Medoo function:" . $method . "-" . json_encode($arguments));
}
self::$dbCurrentConnect = self::$dbConnect[$type];
self::$sqlResut = call_user_func_array([self::$dbConnect[$type], $method], $arguments);
self::$dbCurrentConnect = self::$dbConnect[static::CONFIG_INDEX.':'.$type];
self::$sqlResut = call_user_func_array([self::$dbConnect[static::CONFIG_INDEX.':'.$type], $method], $arguments);
if (!self::catchError($method, $arguments)) {
// 如果失败重试一次
self::$dbCurrentConnect = self::$dbConnect[$type] = self::getConnection($type);
self::$sqlResut = call_user_func_array([self::$dbConnect[$type], $method], $arguments);
self::$dbCurrentConnect = self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
self::$sqlResut = call_user_func_array([self::$dbConnect[static::CONFIG_INDEX.':'.$type], $method], $arguments);
if (!self::catchError($method, $arguments)) {
return false;
}
......@@ -173,11 +173,11 @@ abstract class MysqlBase
*/
public static function getConnection($type, $flush = false)
{
if (!isset(self::$dbConnect[$type]) || $flush) {
self::$dbConnect[$type] = new Medoo(self::getDbConf($type));
if (!isset(self::$dbConnect[static::CONFIG_INDEX.':'.$type]) || $flush) {
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = new Medoo(self::getDbConf($type));
}
return self::$dbConnect[$type];
return self::$dbConnect[static::CONFIG_INDEX.':'.$type];
}
/**
......@@ -402,13 +402,13 @@ abstract class MysqlBase
public static function debug()
{
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
self::$dbConnect[$type]->debug();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
self::$dbConnect[static::CONFIG_INDEX.':'.$type]->debug();
$type = static::READ;
self::$dbConnect[$type] = self::getConnection($type);
self::$dbConnect[$type]->debug();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
self::$dbConnect[static::CONFIG_INDEX.':'.$type]->debug();
return [static::WRITE => self::$dbConnect[static::WRITE], static::READ => self::$dbConnect[static::READ]];
return [static::CONFIG_INDEX.':'.static::WRITE => self::$dbConnect[static::CONFIG_INDEX.':'.static::WRITE], static::CONFIG_INDEX.':'.static::READ => self::$dbConnect[static::CONFIG_INDEX.':'.static::READ]];
}
/**
......@@ -420,11 +420,11 @@ abstract class MysqlBase
{
$ret = [];
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
$ret[$type] = self::$dbConnect[$type]->log();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
$ret[$type] = self::$dbConnect[static::CONFIG_INDEX.':'.$type]->log();
$type = static::READ;
self::$dbConnect[$type] = self::getConnection($type);
$ret[$type] = self::$dbConnect[$type]->log();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
$ret[$type] = self::$dbConnect[static::CONFIG_INDEX.':'.$type]->log();
return $ret;
}
......@@ -447,9 +447,9 @@ abstract class MysqlBase
public static function beginTransaction()
{
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
if(!self::$dbConnect[$type]->pdo->inTransaction()) {
return self::$dbConnect[$type]->pdo->beginTransaction();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
if(!self::$dbConnect[static::CONFIG_INDEX.':'.$type]->pdo->inTransaction()) {
return self::$dbConnect[static::CONFIG_INDEX.':'.$type]->pdo->beginTransaction();
}
return false;
}
......@@ -462,9 +462,9 @@ abstract class MysqlBase
public static function commit()
{
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
if(self::$dbConnect[$type]->pdo->inTransaction()) {
return self::$dbConnect[$type]->pdo->commit();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
if(self::$dbConnect[static::CONFIG_INDEX.':'.$type]->pdo->inTransaction()) {
return self::$dbConnect[static::CONFIG_INDEX.':'.$type]->pdo->commit();
}
return false;
}
......@@ -477,9 +477,9 @@ abstract class MysqlBase
public static function rollback()
{
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
if(self::$dbConnect[$type]->pdo->inTransaction()) {
return self::$dbConnect[$type]->pdo->rollback();
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
if(self::$dbConnect[static::CONFIG_INDEX.':'.$type]->pdo->inTransaction()) {
return self::$dbConnect[static::CONFIG_INDEX.':'.$type]->pdo->rollback();
}
return false;
}
......@@ -492,7 +492,7 @@ abstract class MysqlBase
public static function action(callable $actions)
{
$type = static::WRITE;
self::$dbConnect[$type] = self::getConnection($type);
return self::$dbConnect[$type]->action($actions);
self::$dbConnect[static::CONFIG_INDEX.':'.$type] = self::getConnection($type);
return self::$dbConnect[static::CONFIG_INDEX.':'.$type]->action($actions);
}
}
......@@ -198,7 +198,7 @@ abstract class MysqlClusterBase
}
}
$end_time = microtime(true);
MonUtil::dbMon(self::dbCurrentConnect['server'].'_'.self::dbCurrentConnect['port'] ?? 'unknow_mysql',$method,'mysql',$end_time-$start_time);
MonUtil::dbMon(self::$dbCurrentConnect['server'].'_'.self::$dbCurrentConnect['port'] ?? 'unknow_mysql', $method, 'mysql', $end_time-$start_time);
return self::formatResult($method, $arguments);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment