diff --git a/extdbms/lib/Controllers/DBMS/ServerController.php b/extdbms/lib/Controllers/DBMS/ServerController.php index 416a791..2f01bed 100644 --- a/extdbms/lib/Controllers/DBMS/ServerController.php +++ b/extdbms/lib/Controllers/DBMS/ServerController.php @@ -38,23 +38,20 @@ class ServerController extends DBMSController $lineup_explode = explode('.', $entity->getSpec()); $spec = $lineup_explode[0]; $cpu = $entity->getCPUName(); - $this->getServerService()->getModel()->like("server_cpuname", $cpu, "both"); - $this->getServerService()->getModel()->like("server_spec", $spec, "both"); + $this->getServerService()->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]); $entity->all = $this->getServerService()->getCount(); $this->getServerService()->getModel()->where("server_use_status", "n"); - $this->getServerService()->getModel()->like("server_cpuname", $cpu, "both"); - $this->getServerService()->getModel()->like("server_spec", $spec, "both"); + $this->getServerService()->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]); $entity->use = $this->getServerService()->getCount(); $this->getServerService()->getModel()->where("server_use_status", "y"); - $this->getServerService()->getModel()->like("server_cpuname", $cpu, "both"); - $this->getServerService()->getModel()->like("server_spec", $spec, "both"); + $this->getServerService()->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]); $entity->empty = $this->getServerService()->getCount(); $this->getServerService()->getModel()->where("server_use_status", "y"); - $this->getServerService()->getModel()->like("server_cpuname", $cpu, "both"); $this->getServerService()->getModel()->where("server_fomat_date !='NULL'"); + $this->getServerService()->getModel()->like(["server_cpuname" => "%$cpu%"]); $entity->format = $this->getServerService()->getCount(); return $entity; } diff --git a/extdbms/lib/Database/QueryBuilder.php b/extdbms/lib/Database/QueryBuilder.php index 86a78db..297271a 100644 --- a/extdbms/lib/Database/QueryBuilder.php +++ b/extdbms/lib/Database/QueryBuilder.php @@ -61,8 +61,14 @@ class QueryBuilder { $sql = ''; foreach ($this->where as $index => $clause) { - $boolean = $index === 0 ? '' : $clause['boolean'] . ' '; - $sql .= $boolean . $clause['condition'] . ' '; + if (is_array($clause)) { + $boolean = $index === 0 ? '' : $clause['boolean'] . ' '; + $sql .= $boolean . $clause['condition'] . ' '; + } else { + // 문자열 형태일 경우 (like에서 사용됨) + $boolean = $index === 0 ? '' : 'AND '; + $sql .= $boolean . $clause . ' '; + } } return trim($sql); } @@ -233,8 +239,7 @@ class QueryBuilder //binding까지 완료한 SQL문을 return함 final public function toRawSql(): string { - $sql = $this->buildSelectSql(); - $raw = $sql; + $raw = $this->buildSelectSql(); foreach ($this->bindings as $key => $value) { $escaped = is_numeric($value) ? $value : $this->pdo->quote($value); // 명명된 바인딩 @@ -249,9 +254,10 @@ class QueryBuilder } final public function get(): array { - $sql = $this->buildSelectSql(); if ($this->_debug) { - echo "\n
SQL DEBUG:" . $this->toRawSql() . "
"; + echo php_sapi_name() === 'cli' + ? "\nSQL DEBUG: " . $this->toRawSql() . "\n" + : "
SQL DEBUG: " . $this->toRawSql() . "
"; } $this->latestQuery = $this->toRawSql(); $stmt = $this->pdo->prepare($this->buildSelectSql());