作者 karlet

feat:优化mysqlCli

1 <?php 1 <?php
  2 +
2 namespace Jiaoyin; 3 namespace Jiaoyin;
3 4
4 use Swoole\Database\MysqliConfig; 5 use Swoole\Database\MysqliConfig;
@@ -16,7 +17,7 @@ class MysqlCli @@ -16,7 +17,7 @@ class MysqlCli
16 private $connectConfig = null; 17 private $connectConfig = null;
17 private $database = null; 18 private $database = null;
18 19
19 - public function __construct($host,$port,$database,$username,$password,$charset='utf8',$prefix='', $connectCount = 20) 20 + public function __construct($host, $port, $database, $username, $password, $charset = 'utf8', $prefix = '', $connectCount = 20)
20 { 21 {
21 $this->database = $database; 22 $this->database = $database;
22 $this->prefix = $prefix; 23 $this->prefix = $prefix;
@@ -35,7 +36,7 @@ class MysqlCli @@ -35,7 +36,7 @@ class MysqlCli
35 36
36 private function poolConnect() 37 private function poolConnect()
37 { 38 {
38 - if($this->pool){ 39 + if ($this->pool) {
39 $this->pool->close(); 40 $this->pool->close();
40 } 41 }
41 $this->pool = new MysqliPool((new MysqliConfig) 42 $this->pool = new MysqliPool((new MysqliConfig)
@@ -45,7 +46,7 @@ class MysqlCli @@ -45,7 +46,7 @@ class MysqlCli
45 ->withCharset($this->connectConfig['charset']) 46 ->withCharset($this->connectConfig['charset'])
46 ->withUsername($this->connectConfig['username']) 47 ->withUsername($this->connectConfig['username'])
47 ->withPassword($this->connectConfig['password']) 48 ->withPassword($this->connectConfig['password'])
48 - ,$this->connectConfig['connectCount'] 49 + , $this->connectConfig['connectCount']
49 ); 50 );
50 $this->prefix = $this->connectConfig['prefix']; 51 $this->prefix = $this->connectConfig['prefix'];
51 } 52 }
@@ -116,7 +117,7 @@ class MysqlCli @@ -116,7 +117,7 @@ class MysqlCli
116 $data = $this->execute('SELECT', $sql); 117 $data = $this->execute('SELECT', $sql);
117 $newData = []; 118 $newData = [];
118 if (empty($col)) { 119 if (empty($col)) {
119 - $newsql = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "'.$this->database.'" AND TABLE_NAME="' . $this->parseTable($table) . '" ORDER BY `ORDINAL_POSITION` ASC'; 120 + $newsql = 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = "' . $this->database . '" AND TABLE_NAME="' . $this->parseTable($table) . '" ORDER BY `ORDINAL_POSITION` ASC';
120 $coldata = $this->execute('SELECT', $newsql); 121 $coldata = $this->execute('SELECT', $newsql);
121 if (!$coldata) { 122 if (!$coldata) {
122 return false; 123 return false;
@@ -208,8 +209,12 @@ class MysqlCli @@ -208,8 +209,12 @@ class MysqlCli
208 return false; 209 return false;
209 } 210 }
210 $value[1] = $this->transferValue($value[1]); 211 $value[1] = $this->transferValue($value[1]);
211 - $symbol = isset($value[2]) ? $value[2] : '='; 212 + if ($value[1] === 'NULL') {
  213 + $tmp = $value[0] . ' is NULL';
  214 + } else {
  215 + $symbol = $value[2] ?? '=';
212 $tmp .= $value[0] . ' ' . $symbol . ' ' . $value[1]; 216 $tmp .= $value[0] . ' ' . $symbol . ' ' . $value[1];
  217 + }
213 $tmp .= $key < count($where) - 1 ? ' and ' : ''; 218 $tmp .= $key < count($where) - 1 ? ' and ' : '';
214 } 219 }
215 $whereTxt .= $tmp; 220 $whereTxt .= $tmp;