@@ -8,7 +8,7 @@ |
||
| 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 | |
@@ -8,7 +8,7 @@ |
||
| 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 | |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | // +---------------------------------------------------------------------- |
| 9 | 9 | // | Author: 麦当苗儿 <[email protected]> <http://zjzit.cn> |
| 10 | 10 | // +---------------------------------------------------------------------- |
| 11 | -declare (strict_types = 1); |
|
| 11 | +declare(strict_types=1); |
|
| 12 | 12 | |
| 13 | 13 | namespace think\db\exception; |
| 14 | 14 | |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 | // +---------------------------------------------------------------------- |
| 9 | 9 | // | Author: 麦当苗儿 <[email protected]> <http://zjzit.cn> |
| 10 | 10 | // +---------------------------------------------------------------------- |
| 11 | -declare (strict_types = 1); |
|
| 11 | +declare(strict_types=1); |
|
| 12 | 12 | |
| 13 | 13 | namespace think\db\exception; |
| 14 | 14 | |
@@ -56,8 +56,7 @@ discard block |
||
| 56 | 56 | foreach ($hosts as $i => $host) { |
| 57 | 57 | $port = $ports[$i] ?? $ports[0]; |
| 58 | 58 | $this->options['timeout'] > 0 ? |
| 59 | - $this->handler->addServer($host, (int) $port, $this->options['persistent'], 1, $this->options['timeout']) : |
|
| 60 | - $this->handler->addServer($host, (int) $port, $this->options['persistent'], 1); |
|
| 59 | + $this->handler->addServer($host, (int) $port, $this->options['persistent'], 1, $this->options['timeout']) : $this->handler->addServer($host, (int) $port, $this->options['persistent'], 1); |
|
| 61 | 60 | } |
| 62 | 61 | } |
| 63 | 62 | |
@@ -174,8 +173,7 @@ discard block |
||
| 174 | 173 | $key = $this->getCacheKey($name); |
| 175 | 174 | |
| 176 | 175 | return false === $ttl ? |
| 177 | - $this->handler->delete($key) : |
|
| 178 | - $this->handler->delete($key, $ttl); |
|
| 176 | + $this->handler->delete($key) : $this->handler->delete($key, $ttl); |
|
| 179 | 177 | } |
| 180 | 178 | |
| 181 | 179 | /** |
@@ -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 | |
@@ -158,20 +158,20 @@ discard block |
||
| 158 | 158 | if (false !== strpos($key, '->')) { |
| 159 | 159 | list($key, $name) = explode('->', $key, 2); |
| 160 | 160 | $item = $this->parseKey($query, $key); |
| 161 | - $result[$item] = 'json_set(' . $item . ', \'$.' . $name . '\', ' . $this->parseDataBind($query, $key . '->' . $name, $val, $bind) . ')'; |
|
| 161 | + $result[$item] = 'json_set('.$item.', \'$.'.$name.'\', '.$this->parseDataBind($query, $key.'->'.$name, $val, $bind).')'; |
|
| 162 | 162 | } elseif (false === strpos($key, '.') && !in_array($key, $fields, true)) { |
| 163 | 163 | if ($options['strict']) { |
| 164 | - throw new Exception('fields not exists:[' . $key . ']'); |
|
| 164 | + throw new Exception('fields not exists:['.$key.']'); |
|
| 165 | 165 | } |
| 166 | 166 | } elseif (is_null($val)) { |
| 167 | 167 | $result[$item] = 'NULL'; |
| 168 | 168 | } elseif (is_array($val) && !empty($val)) { |
| 169 | 169 | switch (strtoupper($val[0])) { |
| 170 | 170 | case 'INC': |
| 171 | - $result[$item] = $item . ' + ' . floatval($val[1]); |
|
| 171 | + $result[$item] = $item.' + '.floatval($val[1]); |
|
| 172 | 172 | break; |
| 173 | 173 | case 'DEC': |
| 174 | - $result[$item] = $item . ' - ' . floatval($val[1]); |
|
| 174 | + $result[$item] = $item.' - '.floatval($val[1]); |
|
| 175 | 175 | break; |
| 176 | 176 | } |
| 177 | 177 | } elseif (is_scalar($val)) { |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | $name = $query->bindValue($data, $bind[$key] ?? PDO::PARAM_STR); |
| 202 | 202 | |
| 203 | - return ':' . $name; |
|
| 203 | + return ':'.$name; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | */ |
| 226 | 226 | protected function parseExtra(Query $query, string $extra): string |
| 227 | 227 | { |
| 228 | - return preg_match('/^[\w]+$/i', $extra) ? ' ' . strtoupper($extra) : ''; |
|
| 228 | + return preg_match('/^[\w]+$/i', $extra) ? ' '.strtoupper($extra) : ''; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | if ($field instanceof Raw) { |
| 246 | 246 | $array[] = $field->getValue(); |
| 247 | 247 | } elseif (!is_numeric($key)) { |
| 248 | - $array[] = $this->parseKey($query, $key) . ' AS ' . $this->parseKey($query, $field, true); |
|
| 248 | + $array[] = $this->parseKey($query, $key).' AS '.$this->parseKey($query, $field, true); |
|
| 249 | 249 | } else { |
| 250 | 250 | $array[] = $this->parseKey($query, $field); |
| 251 | 251 | } |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | if ($table instanceof Raw) { |
| 276 | 276 | $item[] = $table->getValue(); |
| 277 | 277 | } elseif (!is_numeric($key)) { |
| 278 | - $item[] = $this->parseKey($query, $key) . ' ' . $this->parseKey($query, $table); |
|
| 278 | + $item[] = $this->parseKey($query, $key).' '.$this->parseKey($query, $table); |
|
| 279 | 279 | } elseif (isset($options['alias'][$table])) { |
| 280 | - $item[] = $this->parseKey($query, $table) . ' ' . $this->parseKey($query, $options['alias'][$table]); |
|
| 280 | + $item[] = $this->parseKey($query, $table).' '.$this->parseKey($query, $options['alias'][$table]); |
|
| 281 | 281 | } else { |
| 282 | 282 | $item[] = $this->parseKey($query, $table); |
| 283 | 283 | } |
@@ -303,11 +303,11 @@ discard block |
||
| 303 | 303 | list($field, $condition) = $options['soft_delete']; |
| 304 | 304 | |
| 305 | 305 | $binds = $query->getFieldsBindType(); |
| 306 | - $whereStr = $whereStr ? '( ' . $whereStr . ' ) AND ' : ''; |
|
| 307 | - $whereStr = $whereStr . $this->parseWhereItem($query, $field, $condition, $binds); |
|
| 306 | + $whereStr = $whereStr ? '( '.$whereStr.' ) AND ' : ''; |
|
| 307 | + $whereStr = $whereStr.$this->parseWhereItem($query, $field, $condition, $binds); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - return empty($whereStr) ? '' : ' WHERE ' . $whereStr; |
|
| 310 | + return empty($whereStr) ? '' : ' WHERE '.$whereStr; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | /** |
@@ -350,17 +350,17 @@ discard block |
||
| 350 | 350 | $where = []; |
| 351 | 351 | foreach ($val as $value) { |
| 352 | 352 | if ($value instanceof Raw) { |
| 353 | - $where[] = ' ' . $logic . ' ( ' . $value->getValue() . ' )'; |
|
| 353 | + $where[] = ' '.$logic.' ( '.$value->getValue().' )'; |
|
| 354 | 354 | continue; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | if (is_array($value)) { |
| 358 | 358 | if (key($value) !== 0) { |
| 359 | - throw new Exception('where express error:' . var_export($value, true)); |
|
| 359 | + throw new Exception('where express error:'.var_export($value, true)); |
|
| 360 | 360 | } |
| 361 | 361 | $field = array_shift($value); |
| 362 | 362 | } elseif (!($value instanceof Closure)) { |
| 363 | - throw new Exception('where express error:' . var_export($value, true)); |
|
| 363 | + throw new Exception('where express error:'.var_export($value, true)); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | if ($value instanceof Closure) { |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | } elseif (is_array($field)) { |
| 370 | 370 | $where[] = $this->parseMultiWhereField($query, $value, $field, $logic, $binds); |
| 371 | 371 | } elseif ($field instanceof Raw) { |
| 372 | - $where[] = ' ' . $logic . ' ' . $this->parseWhereItem($query, $field, $value, $binds); |
|
| 372 | + $where[] = ' '.$logic.' '.$this->parseWhereItem($query, $field, $value, $binds); |
|
| 373 | 373 | } elseif (strpos($field, '|')) { |
| 374 | 374 | $where[] = $this->parseFieldsOr($query, $value, $field, $logic, $binds); |
| 375 | 375 | } elseif (strpos($field, '&')) { |
@@ -377,7 +377,7 @@ discard block |
||
| 377 | 377 | } else { |
| 378 | 378 | // 对字段使用表达式查询 |
| 379 | 379 | $field = is_string($field) ? $field : ''; |
| 380 | - $where[] = ' ' . $logic . ' ' . $this->parseWhereItem($query, $field, $value, $binds); |
|
| 380 | + $where[] = ' '.$logic.' '.$this->parseWhereItem($query, $field, $value, $binds); |
|
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | $item[] = $this->parseWhereItem($query, $k, $value, $binds); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | - return ' ' . $logic . ' ( ' . implode(' AND ', $item) . ' )'; |
|
| 405 | + return ' '.$logic.' ( '.implode(' AND ', $item).' )'; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $item[] = $this->parseWhereItem($query, $k, $value, $binds); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - return ' ' . $logic . ' ( ' . implode(' OR ', $item) . ' )'; |
|
| 426 | + return ' '.$logic.' ( '.implode(' OR ', $item).' )'; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -441,7 +441,7 @@ discard block |
||
| 441 | 441 | $whereClause = $this->buildWhere($query, $newQuery->getOptions('where') ?: []); |
| 442 | 442 | |
| 443 | 443 | if (!empty($whereClause)) { |
| 444 | - $where = ' ' . $logic . ' ( ' . $whereClause . ' )'; |
|
| 444 | + $where = ' '.$logic.' ( '.$whereClause.' )'; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | return $where ?? ''; |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | $where[] = $this->parseWhereItem($query, array_shift($item), $item, $binds); |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - return ' ' . $logic . ' ( ' . implode(' AND ', $where) . ' )'; |
|
| 469 | + return ' '.$logic.' ( '.implode(' AND ', $where).' )'; |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | // 检测操作符 |
| 489 | 489 | if (!is_string($exp)) { |
| 490 | - throw new Exception('where express error:' . var_export($exp, true)); |
|
| 490 | + throw new Exception('where express error:'.var_export($exp, true)); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | $exp = strtoupper($exp); |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | if (is_string($value) && 0 === strpos($value, ':') && $query->isBind(substr($value, 1))) { |
| 513 | 513 | } else { |
| 514 | 514 | $name = $query->bindValue($value, $bindType); |
| 515 | - $value = ':' . $name; |
|
| 515 | + $value = ':'.$name; |
|
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | } |
| 524 | 524 | } |
| 525 | 525 | |
| 526 | - throw new Exception('where express error:' . $exp); |
|
| 526 | + throw new Exception('where express error:'.$exp); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -545,12 +545,12 @@ discard block |
||
| 545 | 545 | $array = []; |
| 546 | 546 | foreach ($value as $item) { |
| 547 | 547 | $name = $query->bindValue($item, PDO::PARAM_STR); |
| 548 | - $array[] = $key . ' ' . $exp . ' :' . $name; |
|
| 548 | + $array[] = $key.' '.$exp.' :'.$name; |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | - $whereStr = '(' . implode(' ' . strtoupper($logic) . ' ', $array) . ')'; |
|
| 551 | + $whereStr = '('.implode(' '.strtoupper($logic).' ', $array).')'; |
|
| 552 | 552 | } else { |
| 553 | - $whereStr = $key . ' ' . $exp . ' ' . $value; |
|
| 553 | + $whereStr = $key.' '.$exp.' '.$value; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | return $whereStr; |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | protected function parseExp(Query $query, string $key, string $exp, Raw $value, string $field, int $bindType): string |
| 571 | 571 | { |
| 572 | 572 | // 表达式查询 |
| 573 | - return '( ' . $key . ' ' . $value->getValue() . ' )'; |
|
| 573 | + return '( '.$key.' '.$value->getValue().' )'; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | list($op, $field) = $value; |
| 591 | 591 | |
| 592 | 592 | if (!in_array(trim($op), ['=', '<>', '>', '>=', '<', '<='])) { |
| 593 | - throw new Exception('where express error:' . var_export($value, true)); |
|
| 593 | + throw new Exception('where express error:'.var_export($value, true)); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - return '( ' . $key . ' ' . $op . ' ' . $this->parseKey($query, $field, true) . ' )'; |
|
| 596 | + return '( '.$key.' '.$op.' '.$this->parseKey($query, $field, true).' )'; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | protected function parseNull(Query $query, string $key, string $exp, $value, $field, int $bindType): string |
| 611 | 611 | { |
| 612 | 612 | // NULL 查询 |
| 613 | - return $key . ' IS ' . $exp; |
|
| 613 | + return $key.' IS '.$exp; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -632,7 +632,7 @@ discard block |
||
| 632 | 632 | $min = $query->bindValue($data[0], $bindType); |
| 633 | 633 | $max = $query->bindValue($data[1], $bindType); |
| 634 | 634 | |
| 635 | - return $key . ' ' . $exp . ' :' . $min . ' AND :' . $max . ' '; |
|
| 635 | + return $key.' '.$exp.' :'.$min.' AND :'.$max.' '; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | /** |
@@ -654,10 +654,10 @@ discard block |
||
| 654 | 654 | } elseif ($value instanceof Raw) { |
| 655 | 655 | $value = $value->getValue(); |
| 656 | 656 | } else { |
| 657 | - throw new Exception('where express error:' . $value); |
|
| 657 | + throw new Exception('where express error:'.$value); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - return $exp . ' ( ' . $value . ' )'; |
|
| 660 | + return $exp.' ( '.$value.' )'; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -673,7 +673,7 @@ discard block |
||
| 673 | 673 | */ |
| 674 | 674 | protected function parseTime(Query $query, string $key, string $exp, $value, $field, int $bindType): string |
| 675 | 675 | { |
| 676 | - return $key . ' ' . substr($exp, 0, 2) . ' ' . $this->parseDateTime($query, $value, $field, $bindType); |
|
| 676 | + return $key.' '.substr($exp, 0, 2).' '.$this->parseDateTime($query, $value, $field, $bindType); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | protected function parseCompare(Query $query, string $key, string $exp, $value, $field, int $bindType): string |
| 691 | 691 | { |
| 692 | 692 | if (is_array($value)) { |
| 693 | - throw new Exception('where express error:' . $exp . var_export($value, true)); |
|
| 693 | + throw new Exception('where express error:'.$exp.var_export($value, true)); |
|
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | // 比较运算 |
@@ -699,10 +699,10 @@ discard block |
||
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | if ('=' == $exp && is_null($value)) { |
| 702 | - return $key . ' IS NULL'; |
|
| 702 | + return $key.' IS NULL'; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | - return $key . ' ' . $exp . ' ' . $value; |
|
| 705 | + return $key.' '.$exp.' '.$value; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | $value = explode(',', $value); |
| 723 | 723 | } |
| 724 | 724 | |
| 725 | - return $key . ' ' . substr($exp, 0, -4) |
|
| 725 | + return $key.' '.substr($exp, 0, -4) |
|
| 726 | 726 | . $this->parseDateTime($query, $value[0], $field, $bindType) |
| 727 | 727 | . ' AND ' |
| 728 | 728 | . $this->parseDateTime($query, $value[1], $field, $bindType); |
@@ -753,18 +753,18 @@ discard block |
||
| 753 | 753 | |
| 754 | 754 | foreach ($value as $v) { |
| 755 | 755 | $name = $query->bindValue($v, $bindType); |
| 756 | - $array[] = ':' . $name; |
|
| 756 | + $array[] = ':'.$name; |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | if (count($array) == 1) { |
| 760 | - return $key . ('IN' == $exp ? ' = ' : ' <> ') . $array[0]; |
|
| 760 | + return $key.('IN' == $exp ? ' = ' : ' <> ').$array[0]; |
|
| 761 | 761 | } else { |
| 762 | 762 | $zone = implode(',', $array); |
| 763 | 763 | $value = empty($zone) ? "''" : $zone; |
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | - return $key . ' ' . $exp . ' (' . $value . ')'; |
|
| 767 | + return $key.' '.$exp.' ('.$value.')'; |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | |
| 828 | 828 | $name = $query->bindValue($value, $bindType); |
| 829 | 829 | |
| 830 | - return ':' . $name; |
|
| 830 | + return ':'.$name; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | */ |
| 840 | 840 | protected function parseLimit(Query $query, string $limit): string |
| 841 | 841 | { |
| 842 | - return (!empty($limit) && false === strpos($limit, '(')) ? ' LIMIT ' . $limit . ' ' : ''; |
|
| 842 | + return (!empty($limit) && false === strpos($limit, '(')) ? ' LIMIT '.$limit.' ' : ''; |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | /** |
@@ -859,14 +859,14 @@ discard block |
||
| 859 | 859 | if (strpos($on, '=')) { |
| 860 | 860 | list($val1, $val2) = explode('=', $on, 2); |
| 861 | 861 | |
| 862 | - $condition = $this->parseKey($query, $val1) . '=' . $this->parseKey($query, $val2); |
|
| 862 | + $condition = $this->parseKey($query, $val1).'='.$this->parseKey($query, $val2); |
|
| 863 | 863 | } else { |
| 864 | 864 | $condition = $on; |
| 865 | 865 | } |
| 866 | 866 | |
| 867 | 867 | $table = $this->parseTable($query, $table); |
| 868 | 868 | |
| 869 | - $joinStr .= ' ' . $type . ' JOIN ' . $table . ' ON ' . $condition; |
|
| 869 | + $joinStr .= ' '.$type.' JOIN '.$table.' ON '.$condition; |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | return $joinStr; |
@@ -891,22 +891,22 @@ discard block |
||
| 891 | 891 | $array[] = $this->parseRand($query); |
| 892 | 892 | } elseif (is_string($val)) { |
| 893 | 893 | if (is_numeric($key)) { |
| 894 | - list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val . ' '); |
|
| 894 | + list($key, $sort) = explode(' ', strpos($val, ' ') ? $val : $val.' '); |
|
| 895 | 895 | } else { |
| 896 | 896 | $sort = $val; |
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | if (preg_match('/^[\w\.]+$/', $key)) { |
| 900 | 900 | $sort = strtoupper($sort); |
| 901 | - $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; |
|
| 902 | - $array[] = $this->parseKey($query, $key, true) . $sort; |
|
| 901 | + $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' '.$sort : ''; |
|
| 902 | + $array[] = $this->parseKey($query, $key, true).$sort; |
|
| 903 | 903 | } else { |
| 904 | - throw new Exception('order express error:' . $key); |
|
| 904 | + throw new Exception('order express error:'.$key); |
|
| 905 | 905 | } |
| 906 | 906 | } |
| 907 | 907 | } |
| 908 | 908 | |
| 909 | - return empty($array) ? '' : ' ORDER BY ' . implode(',', $array); |
|
| 909 | + return empty($array) ? '' : ' ORDER BY '.implode(',', $array); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | /** |
@@ -938,14 +938,14 @@ discard block |
||
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | $sort = strtoupper($sort); |
| 941 | - $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' ' . $sort : ''; |
|
| 941 | + $sort = in_array($sort, ['ASC', 'DESC'], true) ? ' '.$sort : ''; |
|
| 942 | 942 | $bind = $query->getFieldsBindType(); |
| 943 | 943 | |
| 944 | 944 | foreach ($val as $item) { |
| 945 | 945 | $val[] = $this->parseDataBind($query, $key, $item, $bind); |
| 946 | 946 | } |
| 947 | 947 | |
| 948 | - return 'field(' . $this->parseKey($query, $key, true) . ',' . implode(',', $val) . ')' . $sort; |
|
| 948 | + return 'field('.$this->parseKey($query, $key, true).','.implode(',', $val).')'.$sort; |
|
| 949 | 949 | } |
| 950 | 950 | |
| 951 | 951 | /** |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | $val[] = $this->parseKey($query, $key); |
| 971 | 971 | } |
| 972 | 972 | |
| 973 | - return ' GROUP BY ' . implode(',', $val); |
|
| 973 | + return ' GROUP BY '.implode(',', $val); |
|
| 974 | 974 | } |
| 975 | 975 | |
| 976 | 976 | /** |
@@ -982,7 +982,7 @@ discard block |
||
| 982 | 982 | */ |
| 983 | 983 | protected function parseHaving(Query $query, string $having): string |
| 984 | 984 | { |
| 985 | - return !empty($having) ? ' HAVING ' . $having : ''; |
|
| 985 | + return !empty($having) ? ' HAVING '.$having : ''; |
|
| 986 | 986 | } |
| 987 | 987 | |
| 988 | 988 | /** |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $comment = strstr($comment, '*/', true); |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | - return !empty($comment) ? ' /* ' . $comment . ' */' : ''; |
|
| 1001 | + return !empty($comment) ? ' /* '.$comment.' */' : ''; |
|
| 1002 | 1002 | } |
| 1003 | 1003 | |
| 1004 | 1004 | /** |
@@ -1031,13 +1031,13 @@ discard block |
||
| 1031 | 1031 | |
| 1032 | 1032 | foreach ($union as $u) { |
| 1033 | 1033 | if ($u instanceof Closure) { |
| 1034 | - $sql[] = $type . ' ' . $this->parseClosure($query, $u); |
|
| 1034 | + $sql[] = $type.' '.$this->parseClosure($query, $u); |
|
| 1035 | 1035 | } elseif (is_string($u)) { |
| 1036 | - $sql[] = $type . ' ( ' . $u . ' )'; |
|
| 1036 | + $sql[] = $type.' ( '.$u.' )'; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | - return ' ' . implode(' ', $sql); |
|
| 1040 | + return ' '.implode(' ', $sql); |
|
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | 1043 | /** |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | if (is_string($lock) && !empty($lock)) { |
| 1077 | - return ' ' . trim($lock) . ' '; |
|
| 1077 | + return ' '.trim($lock).' '; |
|
| 1078 | 1078 | } else { |
| 1079 | 1079 | return ''; |
| 1080 | 1080 | } |
@@ -1171,7 +1171,7 @@ discard block |
||
| 1171 | 1171 | foreach ($dataSet as $k => $data) { |
| 1172 | 1172 | $data = $this->parseData($query, $data, $allowFields, $bind); |
| 1173 | 1173 | |
| 1174 | - $values[] = 'SELECT ' . implode(',', array_values($data)); |
|
| 1174 | + $values[] = 'SELECT '.implode(',', array_values($data)); |
|
| 1175 | 1175 | |
| 1176 | 1176 | if (!isset($insertFields)) { |
| 1177 | 1177 | $insertFields = array_keys($data); |
@@ -1209,7 +1209,7 @@ discard block |
||
| 1209 | 1209 | $field = $this->parseKey($query, $field, true); |
| 1210 | 1210 | } |
| 1211 | 1211 | |
| 1212 | - return 'INSERT INTO ' . $this->parseTable($query, $table) . ' (' . implode(',', $fields) . ') ' . $this->select($query); |
|
| 1212 | + return 'INSERT INTO '.$this->parseTable($query, $table).' ('.implode(',', $fields).') '.$this->select($query); |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
| 1215 | 1215 | /** |
@@ -1230,7 +1230,7 @@ discard block |
||
| 1230 | 1230 | |
| 1231 | 1231 | $set = []; |
| 1232 | 1232 | foreach ($data as $key => $val) { |
| 1233 | - $set[] = $key . ' = ' . $val; |
|
| 1233 | + $set[] = $key.' = '.$val; |
|
| 1234 | 1234 | } |
| 1235 | 1235 | |
| 1236 | 1236 | return str_replace( |
@@ -1264,7 +1264,7 @@ discard block |
||
| 1264 | 1264 | [ |
| 1265 | 1265 | $this->parseTable($query, $options['table']), |
| 1266 | 1266 | $this->parseExtra($query, $options['extra']), |
| 1267 | - !empty($options['using']) ? ' USING ' . $this->parseTable($query, $options['using']) . ' ' : '', |
|
| 1267 | + !empty($options['using']) ? ' USING '.$this->parseTable($query, $options['using']).' ' : '', |
|
| 1268 | 1268 | $this->parseJoin($query, $options['join']), |
| 1269 | 1269 | $this->parseWhere($query, $options['where']), |
| 1270 | 1270 | $this->parseOrder($query, $options['order']), |
@@ -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 | |
@@ -449,9 +449,9 @@ discard block |
||
| 449 | 449 | } else { |
| 450 | 450 | if (true === $key) { |
| 451 | 451 | if (!empty($query->getOptions('key'))) { |
| 452 | - $key = 'think:' . $this->getConfig('database') . '.' . $query->getTable() . '|' . $query->getOptions('key'); |
|
| 452 | + $key = 'think:'.$this->getConfig('database').'.'.$query->getTable().'|'.$query->getOptions('key'); |
|
| 453 | 453 | } else { |
| 454 | - $key = md5($this->getConfig('database') . serialize($query->getOptions())); |
|
| 454 | + $key = md5($this->getConfig('database').serialize($query->getOptions())); |
|
| 455 | 455 | } |
| 456 | 456 | } |
| 457 | 457 | |
@@ -475,15 +475,15 @@ discard block |
||
| 475 | 475 | */ |
| 476 | 476 | public function lazyWrite(string $type, string $guid, float $step, int $lazyTime) |
| 477 | 477 | { |
| 478 | - if (!$this->cache->has($guid . '_time')) { |
|
| 478 | + if (!$this->cache->has($guid.'_time')) { |
|
| 479 | 479 | // 计时开始 |
| 480 | - $this->cache->set($guid . '_time', time(), 0); |
|
| 480 | + $this->cache->set($guid.'_time', time(), 0); |
|
| 481 | 481 | $this->cache->$type($guid, $step); |
| 482 | - } elseif (time() > $this->cache->get($guid . '_time') + $lazyTime) { |
|
| 482 | + } elseif (time() > $this->cache->get($guid.'_time') + $lazyTime) { |
|
| 483 | 483 | // 删除缓存 |
| 484 | 484 | $value = $this->cache->$type($guid, $step); |
| 485 | 485 | $this->cache->delete($guid); |
| 486 | - $this->cache->delete($guid . '_time'); |
|
| 486 | + $this->cache->delete($guid.'_time'); |
|
| 487 | 487 | return 0 === $value ? false : $value; |
| 488 | 488 | } else { |
| 489 | 489 | // 更新缓存 |
@@ -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 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | { |
| 62 | 62 | $this->query->parseOptions(); |
| 63 | 63 | |
| 64 | - $field = $aggregate . '(' . $this->builder->parseKey($this->query, $field) . ') AS tp_' . strtolower($aggregate); |
|
| 64 | + $field = $aggregate.'('.$this->builder->parseKey($this->query, $field).') AS tp_'.strtolower($aggregate); |
|
| 65 | 65 | |
| 66 | 66 | return $this->value($field, 0, false); |
| 67 | 67 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | if ($key && '*' != $field) { |
| 114 | - $field = $key . ',' . $field; |
|
| 114 | + $field = $key.','.$field; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $field = array_map('trim', explode(',', $field)); |
@@ -421,7 +421,7 @@ discard block |
||
| 421 | 421 | if (!empty($options['group'])) { |
| 422 | 422 | // 支持GROUP |
| 423 | 423 | $bind = $this->query->getBind(); |
| 424 | - $subSql = $this->query->options($options)->field('count(' . $field . ') AS think_count')->bind($bind)->buildSql(); |
|
| 424 | + $subSql = $this->query->options($options)->field('count('.$field.') AS think_count')->bind($bind)->buildSql(); |
|
| 425 | 425 | |
| 426 | 426 | $query = $this->query->newQuery()->table([$subSql => '_group_count_']); |
| 427 | 427 | |
@@ -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\connector; |
| 14 | 14 | |
@@ -81,16 +81,16 @@ discard block |
||
| 81 | 81 | protected function parseDsn(array $config): string |
| 82 | 82 | { |
| 83 | 83 | if (!empty($config['socket'])) { |
| 84 | - $dsn = 'mysql:unix_socket=' . $config['socket']; |
|
| 84 | + $dsn = 'mysql:unix_socket='.$config['socket']; |
|
| 85 | 85 | } elseif (!empty($config['hostport'])) { |
| 86 | - $dsn = 'mysql:host=' . $config['hostname'] . ';port=' . $config['hostport']; |
|
| 86 | + $dsn = 'mysql:host='.$config['hostname'].';port='.$config['hostport']; |
|
| 87 | 87 | } else { |
| 88 | - $dsn = 'mysql:host=' . $config['hostname']; |
|
| 88 | + $dsn = 'mysql:host='.$config['hostname']; |
|
| 89 | 89 | } |
| 90 | - $dsn .= ';dbname=' . $config['database']; |
|
| 90 | + $dsn .= ';dbname='.$config['database']; |
|
| 91 | 91 | |
| 92 | 92 | if (!empty($config['charset'])) { |
| 93 | - $dsn .= ';charset=' . $config['charset']; |
|
| 93 | + $dsn .= ';charset='.$config['charset']; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | return $dsn; |
@@ -110,10 +110,10 @@ discard block |
||
| 110 | 110 | if (strpos($tableName, '.')) { |
| 111 | 111 | $tableName = str_replace('.', '`.`', $tableName); |
| 112 | 112 | } |
| 113 | - $tableName = '`' . $tableName . '`'; |
|
| 113 | + $tableName = '`'.$tableName.'`'; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - $sql = 'SHOW FULL COLUMNS FROM ' . $tableName; |
|
| 116 | + $sql = 'SHOW FULL COLUMNS FROM '.$tableName; |
|
| 117 | 117 | $pdo = $this->getPDOStatement($sql); |
| 118 | 118 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); |
| 119 | 119 | $info = []; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function getTables(string $dbName = ''): array |
| 147 | 147 | { |
| 148 | - $sql = !empty($dbName) ? 'SHOW TABLES FROM ' . $dbName : 'SHOW TABLES '; |
|
| 148 | + $sql = !empty($dbName) ? 'SHOW TABLES FROM '.$dbName : 'SHOW TABLES '; |
|
| 149 | 149 | $pdo = $this->getPDOStatement($sql); |
| 150 | 150 | $result = $pdo->fetchAll(PDO::FETCH_ASSOC); |
| 151 | 151 | $info = []; |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | */ |
| 166 | 166 | protected function getExplain(string $sql): array |
| 167 | 167 | { |
| 168 | - $pdo = $this->linkID->query("EXPLAIN " . $sql); |
|
| 168 | + $pdo = $this->linkID->query("EXPLAIN ".$sql); |
|
| 169 | 169 | $result = $pdo->fetch(PDO::FETCH_ASSOC); |
| 170 | 170 | $result = array_change_key_case($result); |
| 171 | 171 | |
| 172 | 172 | if (isset($result['extra'])) { |
| 173 | 173 | if (strpos($result['extra'], 'filesort') || strpos($result['extra'], 'temporary')) { |
| 174 | - $this->log('SQL:' . $this->queryStr . '[' . $result['extra'] . ']', 'warn'); |
|
| 174 | + $this->log('SQL:'.$this->queryStr.'['.$result['extra'].']', 'warn'); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |