dbms_primeidc_init...1
This commit is contained in:
parent
4bc1a810ab
commit
953e6abe65
@ -19,32 +19,4 @@ class ServerController extends DBMSController
|
||||
}
|
||||
return $this->_serverService;
|
||||
}
|
||||
//가용장비 현황 server_use.php
|
||||
//CLI 접속방법 : php index.php site/server/use
|
||||
//WEB 접속방법 : http://localhost site/server/use
|
||||
private function setMode(GearlistEntity $entity): GearlistEntity
|
||||
{
|
||||
$lineup_explode = explode('.', $entity->getSpec());
|
||||
$spec = $lineup_explode[0];
|
||||
$cpu = $entity->getCPUName();
|
||||
$entity->all = $this->getServerService()->getCountByMode("all", $cpu, $spec);
|
||||
$entity->use = $this->getServerService()->getCountByMode("use", $cpu, $spec);
|
||||
$entity->empty = $this->getServerService()->getCountByMode("empty", $cpu, $spec);
|
||||
$entity->format = $this->getServerService()->getCountByMode("format", $cpu, $spec);
|
||||
return $entity;
|
||||
}
|
||||
public function index(array $params): string
|
||||
{
|
||||
$gearlistEntities = $this->getGearlistService()->getEntitiesForLineUp();
|
||||
//DB에 넣지않는 이유가 뭘까? DB에 넣으면 관리가 힘들어서?
|
||||
$gearlistEntities[] = new GearlistEntity(['process' => "INTEL i5(구세대)", 'spec' => "i5-2.xx", "cpuname" => "i5-2", 'price' => "23"]);
|
||||
$gearlistEntities[] = new GearlistEntity(['process' => "INTEL i7(구세대)", 'spec' => "i7-2.xx", "cpuname" => "i7-2", 'price' => "45"]);
|
||||
$gearlistEntities[] = new GearlistEntity(['process' => "INTEL i7(4세대)", 'spec' => "i7-4.xx", "cpuname" => "i7-4", 'price' => "45"]);
|
||||
$entities = [];
|
||||
foreach ($gearlistEntities as $idx => $gearlistEntity) {
|
||||
$entities[] = $this->setMode($gearlistEntity);
|
||||
}
|
||||
$this->entities = $entities;
|
||||
return $this->render(__FUNCTION__);
|
||||
}
|
||||
} //Class
|
||||
|
||||
@ -297,29 +297,36 @@ class QueryBuilder
|
||||
}
|
||||
|
||||
//CUD부분
|
||||
final public function insert(array $data): bool
|
||||
final public function insert(array $data): bool|int
|
||||
{
|
||||
$columns = [];
|
||||
$placeholders = [];
|
||||
$this->bindings = [];
|
||||
|
||||
foreach ($data as $col => $val) {
|
||||
$safePlaceholder = ':i_' . count($this->bindings);
|
||||
if ($val === null) {
|
||||
// $val이 null이면 $col을 그대로 SQL로 사용
|
||||
$columns[] = ''; // placeholder로 인해 생략
|
||||
$placeholders[] = $col; // 예: col2=(SELECT something)
|
||||
// null 값인 경우 SQL 조각으로 처리
|
||||
$placeholders[] = $col;
|
||||
} else {
|
||||
$safePlaceholder = ':i_' . preg_replace('/\W+/', '_', $col); // 안전한 바인딩 키
|
||||
$columns[] = $col;
|
||||
$placeholders[] = $safePlaceholder;
|
||||
$this->bindings[$safePlaceholder] = $val;
|
||||
}
|
||||
}
|
||||
$sql = "INSERT INTO {$this->table} (" . implode(', ', array_filter($columns)) . ") "
|
||||
. "VALUES (" . implode(', ', $placeholders) . ")";
|
||||
|
||||
$columnsSql = $columns ? '(' . implode(', ', $columns) . ')' : '';
|
||||
$placeholdersSql = '(' . implode(', ', $placeholders) . ')';
|
||||
|
||||
$sql = "INSERT INTO {$this->table} {$columnsSql} VALUES {$placeholdersSql}";
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
foreach ($this->bindings as $k => $v) {
|
||||
$stmt->bindValue($k, $v);
|
||||
foreach ($this->bindings as $key => $value) {
|
||||
$stmt->bindValue($key, $value);
|
||||
}
|
||||
return $stmt->execute() && $stmt->rowCount() > 0 ? (int)$this->pdo->lastInsertId() : false;
|
||||
|
||||
$result = $stmt->execute();
|
||||
return $result && $stmt->rowCount() > 0 ? (int)$this->pdo->lastInsertId() : false;
|
||||
}
|
||||
|
||||
final public function update(array $data): bool
|
||||
@ -327,6 +334,7 @@ class QueryBuilder
|
||||
if (empty($this->where)) {
|
||||
throw new \Exception(__FUNCTION__ . " 구문은 WHERE절 없이 사용할수 없습니다.");
|
||||
}
|
||||
|
||||
$setParts = [];
|
||||
foreach ($data as $col => $val) {
|
||||
if ($val === null) {
|
||||
@ -338,8 +346,10 @@ class QueryBuilder
|
||||
$this->bindings[$placeholder] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "UPDATE {$this->table} SET " . implode(', ', $setParts)
|
||||
. " WHERE " . implode(' AND ', $this->where);
|
||||
. " WHERE " . $this->buildWhereSql(); // <<< 수정된 부분
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
foreach ($this->bindings as $k => $v) {
|
||||
$stmt->bindValue($k, $v);
|
||||
@ -350,13 +360,16 @@ class QueryBuilder
|
||||
final public function delete(): bool
|
||||
{
|
||||
if (empty($this->where)) {
|
||||
throw new \Exception(__FUNCTION__ . " 구문은 WHERE절 없이 사용할수 없습니다.");
|
||||
throw new \Exception("DELETE 문에는 WHERE 절이 반드시 필요합니다.");
|
||||
}
|
||||
$sql = "DELETE FROM {$this->table} WHERE " . implode(' AND ', $this->where);
|
||||
|
||||
$sql = "DELETE FROM {$this->table} WHERE " . $this->buildWhereSql();
|
||||
|
||||
$stmt = $this->pdo->prepare($sql);
|
||||
foreach ($this->bindings as $k => $v) {
|
||||
$stmt->bindValue($k, $v);
|
||||
foreach ($this->bindings as $key => $value) {
|
||||
$stmt->bindValue($key, $value);
|
||||
}
|
||||
|
||||
return $stmt->execute();
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user