@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare (strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\db; |
14 | 14 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function getBuilderClass(): string |
138 | 138 | { |
139 | - return $this->getConfig('builder') ?: '\\think\\db\\builder\\' . ucfirst($this->getConfig('type')); |
|
139 | + return $this->getConfig('builder') ?: '\\think\\db\\builder\\'.ucfirst($this->getConfig('type')); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -246,14 +246,14 @@ discard block |
||
246 | 246 | list($tableName) = explode(' ', $tableName); |
247 | 247 | |
248 | 248 | if (!strpos($tableName, '.')) { |
249 | - $schema = $this->getConfig('database') . '.' . $tableName; |
|
249 | + $schema = $this->getConfig('database').'.'.$tableName; |
|
250 | 250 | } else { |
251 | 251 | $schema = $tableName; |
252 | 252 | } |
253 | 253 | |
254 | 254 | if (!isset($this->info[$schema])) { |
255 | 255 | // 读取缓存 |
256 | - $cacheFile = Container::pull('app')->getRuntimePath() . 'schema' . DIRECTORY_SEPARATOR . $schema . '.php'; |
|
256 | + $cacheFile = Container::pull('app')->getRuntimePath().'schema'.DIRECTORY_SEPARATOR.$schema.'.php'; |
|
257 | 257 | |
258 | 258 | if (!$this->config['debug'] && is_file($cacheFile)) { |
259 | 259 | $info = include $cacheFile; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | } |
263 | 263 | |
264 | 264 | $fields = array_keys($info); |
265 | - $bind = $type = []; |
|
265 | + $bind = $type = []; |
|
266 | 266 | |
267 | 267 | foreach ($info as $key => $val) { |
268 | 268 | // 记录字段类型 |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | $startTime = microtime(true); |
382 | 382 | $this->links[$linkNum] = $this->createPdo($config['dsn'], $config['username'], $config['password'], $params); |
383 | 383 | // 记录数据库连接信息 |
384 | - $this->log('CONNECT:[ UseTime:' . number_format(microtime(true) - $startTime, 6) . 's ] ' . $config['dsn']); |
|
384 | + $this->log('CONNECT:[ UseTime:'.number_format(microtime(true) - $startTime, 6).'s ] '.$config['dsn']); |
|
385 | 385 | |
386 | 386 | return $this->links[$linkNum]; |
387 | 387 | } catch (\PDOException $e) { |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | |
644 | 644 | if (!$result) { |
645 | 645 | // 执行查询 |
646 | - $resultSet = $this->query($query, function ($query) { |
|
646 | + $resultSet = $this->query($query, function($query) { |
|
647 | 647 | return $this->builder->select($query, true); |
648 | 648 | }); |
649 | 649 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | |
689 | 689 | if (!$resultSet) { |
690 | 690 | // 执行查询操作 |
691 | - $resultSet = $this->query($query, function ($query) { |
|
691 | + $resultSet = $this->query($query, function($query) { |
|
692 | 692 | return $this->builder->select($query); |
693 | 693 | }); |
694 | 694 | } |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | list($distinct, $field) = explode(' ', $field); |
922 | 922 | } |
923 | 923 | |
924 | - $field = $aggregate . '(' . (!empty($distinct) ? 'DISTINCT ' : '') . $this->builder->parseKey($query, $field, true) . ') AS tp_' . strtolower($aggregate); |
|
924 | + $field = $aggregate.'('.(!empty($distinct) ? 'DISTINCT ' : '').$this->builder->parseKey($query, $field, true).') AS tp_'.strtolower($aggregate); |
|
925 | 925 | |
926 | 926 | $result = $this->value($query, $field, 0, false); |
927 | 927 | |
@@ -945,7 +945,7 @@ discard block |
||
945 | 945 | } |
946 | 946 | |
947 | 947 | if ($key && '*' != $column) { |
948 | - $field = $key . ',' . $column; |
|
948 | + $field = $key.','.$column; |
|
949 | 949 | } else { |
950 | 950 | $field = $column; |
951 | 951 | } |
@@ -1016,15 +1016,14 @@ discard block |
||
1016 | 1016 | $type = is_array($val) ? $val[1] : PDO::PARAM_STR; |
1017 | 1017 | |
1018 | 1018 | if ((self::PARAM_FLOAT == $type || PDO::PARAM_STR == $type) && is_string($value)) { |
1019 | - $value = '\'' . addslashes($value) . '\''; |
|
1019 | + $value = '\''.addslashes($value).'\''; |
|
1020 | 1020 | } elseif (PDO::PARAM_INT == $type && '' === $value) { |
1021 | 1021 | $value = 0; |
1022 | 1022 | } |
1023 | 1023 | |
1024 | 1024 | // 判断占位符 |
1025 | 1025 | $sql = is_numeric($key) ? |
1026 | - substr_replace($sql, $value, strpos($sql, '?'), 1) : |
|
1027 | - substr_replace($sql, $value, strpos($sql, ':' . $key), strlen(':' . $key)); |
|
1026 | + substr_replace($sql, $value, strpos($sql, '?'), 1) : substr_replace($sql, $value, strpos($sql, ':'.$key), strlen(':'.$key)); |
|
1028 | 1027 | } |
1029 | 1028 | |
1030 | 1029 | return rtrim($sql); |
@@ -1043,7 +1042,7 @@ discard block |
||
1043 | 1042 | { |
1044 | 1043 | foreach ($bind as $key => $val) { |
1045 | 1044 | // 占位符 |
1046 | - $param = is_numeric($key) ? $key + 1 : ':' . $key; |
|
1045 | + $param = is_numeric($key) ? $key + 1 : ':'.$key; |
|
1047 | 1046 | |
1048 | 1047 | if (is_array($val)) { |
1049 | 1048 | if (PDO::PARAM_INT == $val[1] && '' === $val[0]) { |
@@ -1079,7 +1078,7 @@ discard block |
||
1079 | 1078 | protected function bindParam(array $bind): void |
1080 | 1079 | { |
1081 | 1080 | foreach ($bind as $key => $val) { |
1082 | - $param = is_numeric($key) ? $key + 1 : ':' . $key; |
|
1081 | + $param = is_numeric($key) ? $key + 1 : ':'.$key; |
|
1083 | 1082 | |
1084 | 1083 | if (is_array($val)) { |
1085 | 1084 | array_unshift($val, $param); |
@@ -1187,7 +1186,7 @@ discard block |
||
1187 | 1186 | $this->linkID->beginTransaction(); |
1188 | 1187 | } elseif ($this->transTimes > 1 && $this->supportSavepoint()) { |
1189 | 1188 | $this->linkID->exec( |
1190 | - $this->parseSavepoint('trans' . $this->transTimes) |
|
1189 | + $this->parseSavepoint('trans'.$this->transTimes) |
|
1191 | 1190 | ); |
1192 | 1191 | } |
1193 | 1192 | } catch (\Exception $e) { |
@@ -1230,7 +1229,7 @@ discard block |
||
1230 | 1229 | $this->linkID->rollBack(); |
1231 | 1230 | } elseif ($this->transTimes > 1 && $this->supportSavepoint()) { |
1232 | 1231 | $this->linkID->exec( |
1233 | - $this->parseSavepointRollBack('trans' . $this->transTimes) |
|
1232 | + $this->parseSavepointRollBack('trans'.$this->transTimes) |
|
1234 | 1233 | ); |
1235 | 1234 | } |
1236 | 1235 | |
@@ -1254,7 +1253,7 @@ discard block |
||
1254 | 1253 | */ |
1255 | 1254 | protected function parseSavepoint(string $name): string |
1256 | 1255 | { |
1257 | - return 'SAVEPOINT ' . $name; |
|
1256 | + return 'SAVEPOINT '.$name; |
|
1258 | 1257 | } |
1259 | 1258 | |
1260 | 1259 | /** |
@@ -1265,7 +1264,7 @@ discard block |
||
1265 | 1264 | */ |
1266 | 1265 | protected function parseSavepointRollBack(string $name): string |
1267 | 1266 | { |
1268 | - return 'ROLLBACK TO SAVEPOINT ' . $name; |
|
1267 | + return 'ROLLBACK TO SAVEPOINT '.$name; |
|
1269 | 1268 | } |
1270 | 1269 | |
1271 | 1270 | /** |
@@ -1403,13 +1402,13 @@ discard block |
||
1403 | 1402 | { |
1404 | 1403 | if ($this->PDOStatement) { |
1405 | 1404 | $error = $this->PDOStatement->errorInfo(); |
1406 | - $error = $error[1] . ':' . $error[2]; |
|
1405 | + $error = $error[1].':'.$error[2]; |
|
1407 | 1406 | } else { |
1408 | 1407 | $error = ''; |
1409 | 1408 | } |
1410 | 1409 | |
1411 | 1410 | if ('' != $this->queryStr) { |
1412 | - $error .= "\n [ SQL语句 ] : " . $this->getLastsql(); |
|
1411 | + $error .= "\n [ SQL语句 ] : ".$this->getLastsql(); |
|
1413 | 1412 | } |
1414 | 1413 | |
1415 | 1414 | return $error; |
@@ -1473,10 +1472,10 @@ discard block |
||
1473 | 1472 | } |
1474 | 1473 | |
1475 | 1474 | // 未注册监听则记录到日志中 |
1476 | - $this->log($sql . ' [ ' . $master . 'RunTime:' . $runtime . 's ]'); |
|
1475 | + $this->log($sql.' [ '.$master.'RunTime:'.$runtime.'s ]'); |
|
1477 | 1476 | |
1478 | 1477 | if (!empty($explain)) { |
1479 | - $this->log('[ EXPLAIN : ' . var_export($explain, true) . ' ]'); |
|
1478 | + $this->log('[ EXPLAIN : '.var_export($explain, true).' ]'); |
|
1480 | 1479 | } |
1481 | 1480 | } |
1482 | 1481 | } |
@@ -1578,9 +1577,9 @@ discard block |
||
1578 | 1577 | } else { |
1579 | 1578 | if (true === $key) { |
1580 | 1579 | if (!empty($query->getOptions('key'))) { |
1581 | - $key = 'think:' . $this->getConfig('database') . '.' . $query->getTable() . '|' . $query->getOptions('key'); |
|
1580 | + $key = 'think:'.$this->getConfig('database').'.'.$query->getTable().'|'.$query->getOptions('key'); |
|
1582 | 1581 | } else { |
1583 | - $key = md5($this->getConfig('database') . serialize($query->getOptions()) . serialize($query->getBind(false))); |
|
1582 | + $key = md5($this->getConfig('database').serialize($query->getOptions()).serialize($query->getBind(false))); |
|
1584 | 1583 | } |
1585 | 1584 | } |
1586 | 1585 |