Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
php_utils
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
php_utils
Commits
16949fb7
Commit
16949fb7
authored
Jun 26, 2021
by
cuiweifeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update : mysql add configindex
parent
68a14dcd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
31 deletions
+31
-31
MysqlBase.php
src/Mysql/MysqlBase.php
+30
-30
MysqlClusterBase.php
src/Mysql/MysqlClusterBase.php
+1
-1
No files found.
src/Mysql/MysqlBase.php
View file @
16949fb7
...
...
@@ -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
);
}
}
src/Mysql/MysqlClusterBase.php
View file @
16949fb7
...
...
@@ -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
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment