|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Jiaoyin;
|
|
|
|
|
|
|
|
use Swoole\Database\MysqliConfig;
|
|
...
|
...
|
@@ -10,24 +11,24 @@ class MysqlCli |
|
|
|
private $pool = null;
|
|
|
|
private $prefix = '';// 前缀
|
|
|
|
|
|
|
|
private int $reconnectCount = 0; //period时间内重连次数
|
|
|
|
private int $period = 300;
|
|
|
|
private int $reconnectCount = 0; //period时间内重连次数
|
|
|
|
private int $period = 300;
|
|
|
|
private int $lastReconnectTime = 0;
|
|
|
|
private $connectConfig = null;
|
|
|
|
private $database = null;
|
|
|
|
private $connectConfig = null;
|
|
|
|
private $database = null;
|
|
|
|
|
|
|
|
public function __construct($host,$port,$database,$username,$password,$charset='utf8',$prefix='', $connectCount = 20)
|
|
|
|
public function __construct($host, $port, $database, $username, $password, $charset = 'utf8', $prefix = '', $connectCount = 20)
|
|
|
|
{
|
|
|
|
$this->database = $database;
|
|
|
|
$this->prefix = $prefix;
|
|
|
|
$this->database = $database;
|
|
|
|
$this->prefix = $prefix;
|
|
|
|
$this->connectConfig = [
|
|
|
|
'host' => $host,
|
|
|
|
'port' => $port,
|
|
|
|
'database' => $database,
|
|
|
|
'username' => $username,
|
|
|
|
'password' => $password,
|
|
|
|
'charset' => $charset,
|
|
|
|
'prefix' => $prefix,
|
|
|
|
'host' => $host,
|
|
|
|
'port' => $port,
|
|
|
|
'database' => $database,
|
|
|
|
'username' => $username,
|
|
|
|
'password' => $password,
|
|
|
|
'charset' => $charset,
|
|
|
|
'prefix' => $prefix,
|
|
|
|
'connectCount' => $connectCount,
|
|
|
|
];
|
|
|
|
$this->poolConnect();
|
|
...
|
...
|
@@ -35,17 +36,17 @@ class MysqlCli |
|
|
|
|
|
|
|
private function poolConnect()
|
|
|
|
{
|
|
|
|
if($this->pool){
|
|
|
|
if ($this->pool) {
|
|
|
|
$this->pool->close();
|
|
|
|
}
|
|
|
|
$this->pool = new MysqliPool((new MysqliConfig)
|
|
|
|
$this->pool = new MysqliPool((new MysqliConfig)
|
|
|
|
->withHost($this->connectConfig['host'])
|
|
|
|
->withPort($this->connectConfig['port'])
|
|
|
|
->withDbName($this->connectConfig['database'])
|
|
|
|
->withCharset($this->connectConfig['charset'])
|
|
|
|
->withUsername($this->connectConfig['username'])
|
|
|
|
->withPassword($this->connectConfig['password'])
|
|
|
|
,$this->connectConfig['connectCount']
|
|
|
|
, $this->connectConfig['connectCount']
|
|
|
|
);
|
|
|
|
$this->prefix = $this->connectConfig['prefix'];
|
|
|
|
}
|
|
...
|
...
|
@@ -116,7 +117,7 @@ class MysqlCli |
|
|
|
$data = $this->execute('SELECT', $sql);
|
|
|
|
$newData = [];
|
|
|
|
if (empty($col)) {
|
|
|
|
$newsql = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'.$this->database.'" AND TABLE_NAME="' . $this->parseTable($table) . '" ORDER BY `ORDINAL_POSITION` ASC';
|
|
|
|
$newsql = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "' . $this->database . '" AND TABLE_NAME="' . $this->parseTable($table) . '" ORDER BY `ORDINAL_POSITION` ASC';
|
|
|
|
$coldata = $this->execute('SELECT', $newsql);
|
|
|
|
if (!$coldata) {
|
|
|
|
return false;
|
|
...
|
...
|
@@ -208,9 +209,13 @@ class MysqlCli |
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$value[1] = $this->transferValue($value[1]);
|
|
|
|
$symbol = isset($value[2]) ? $value[2] : '=';
|
|
|
|
$tmp .= $value[0] . ' ' . $symbol . ' ' . $value[1];
|
|
|
|
$tmp .= $key < count($where) - 1 ? ' and ' : '';
|
|
|
|
if ($value[1] === 'NULL') {
|
|
|
|
$tmp = $value[0] . ' is NULL';
|
|
|
|
} else {
|
|
|
|
$symbol = $value[2] ?? '=';
|
|
|
|
$tmp .= $value[0] . ' ' . $symbol . ' ' . $value[1];
|
|
|
|
}
|
|
|
|
$tmp .= $key < count($where) - 1 ? ' and ' : '';
|
|
|
|
}
|
|
|
|
$whereTxt .= $tmp;
|
|
|
|
} else {
|
...
|
...
|
|