dbms_primeidc_init...1
This commit is contained in:
parent
182a73fa9d
commit
ca0fa67f13
@ -11,7 +11,7 @@ abstract class Model
|
||||
private $_db = null;
|
||||
private $_debug = false;
|
||||
private $_reset = true;
|
||||
private $_querys = ["SELECT" => "SELECT *", "JOIN" => "", "ORDERBY" => "", "LIMIT" => ""];
|
||||
private $_querys = [];
|
||||
private $_wheres = [];
|
||||
private $_lastQuery = "";
|
||||
protected function __construct() {} //
|
||||
@ -55,13 +55,13 @@ abstract class Model
|
||||
private function reset(): void
|
||||
{
|
||||
$this->_wheres = [];
|
||||
$this->_querys = ["SELECT" => "SELECT *", "JOIN" => "", "ORDERBY" => "", "LIMIT" => ""];
|
||||
$this->_querys = ["SELECT" => "SELECT *", "JOIN" => "", "ORDERBY" => "", "LIKE" => "", "LIMIT" => ""];
|
||||
}
|
||||
final public function getLastQuery(): string
|
||||
{
|
||||
return $this->_lastQuery;
|
||||
}
|
||||
private function getValue(mixed $values): string|null
|
||||
private function makeValue(mixed $values): string|null
|
||||
{
|
||||
if ($values === null) {
|
||||
return $values;
|
||||
@ -81,11 +81,11 @@ abstract class Model
|
||||
$temps = [];
|
||||
if (is_array($columns)) {
|
||||
foreach ($columns as $column => $value) {
|
||||
$value = $this->getValue($value);
|
||||
$value = $this->makeValue($value);
|
||||
$temps[] = sprintf("%s%s", $column, $value === null ? "" : "=" . $value);
|
||||
}
|
||||
} else {
|
||||
$value = $this->getValue($values);
|
||||
$value = $this->makeValue($values);
|
||||
$temps[] = sprintf("%s%s", $columns, $value === null ? "" : "=" . $value);
|
||||
}
|
||||
// throw new \Exception("DATA:" . $columns . $value === null ? "NULL" : $value);
|
||||
@ -107,7 +107,7 @@ abstract class Model
|
||||
}
|
||||
final public function whereIn(string $column, array $values, string $delimeter = "AND", $range = "IN")
|
||||
{
|
||||
$query = " {$column} {$range} (" . $this->getValue($values) . ")";
|
||||
$query = " {$column} {$range} (" . $this->makeValue($values) . ")";
|
||||
$this->_wheres[] = count($this->_wheres) ? $delimeter . " " . $query : $query;
|
||||
}
|
||||
final public function whereNotIn(string $column, array $values, string $delimeter = "AND", $range = "NOT IN")
|
||||
@ -180,23 +180,24 @@ abstract class Model
|
||||
}
|
||||
|
||||
//Result
|
||||
private function makeResultQuery(string $head, string $tail = ""): string
|
||||
{
|
||||
return "{$head} FROM {$this->getTable()} {$this->_querys['JOIN']} {$this->getWhere()} {$this->_querys['LIKE']} {$tail}";
|
||||
}
|
||||
public function getResult($mode = PDO::FETCH_ASSOC): mixed
|
||||
{
|
||||
$query = "{$this->_querys['SELECT']} FROM {$this->getTable()} {$this->_querys['JOIN']} {$this->getWhere()} {$this->_querys['ORDERBY']} {$this->_querys['LIMIT']}";
|
||||
$stmt = $this->execute($query);
|
||||
$stmt = $this->execute($this->makeResultQuery($this->_querys['SELECT'], "{$this->_querys['ORDERBY']} {$this->_querys['LIMIT']}"));
|
||||
return $stmt->fetch($mode);
|
||||
}
|
||||
public function getResults($mode = PDO::FETCH_ASSOC): mixed
|
||||
{
|
||||
$query = "{$this->_querys["SELECT"]} FROM {$this->getTable()} {$this->_querys['JOIN']} {$this->getWhere()} {$this->_querys['ORDERBY']} {$this->_querys['LIMIT']}";
|
||||
$stmt = $this->execute($query);
|
||||
$stmt = $this->execute($this->makeResultQuery($this->_querys['SELECT'], "{$this->_querys['ORDERBY']} {$this->_querys['LIMIT']}"));
|
||||
return $stmt->fetchAll($mode);
|
||||
}
|
||||
final public function countAllResults(string $column = "*", $reset = true): int
|
||||
{
|
||||
$this->_reset = $reset;
|
||||
$query = "SELECT COUNT({$column}) FROM {$this->getTable()} {$this->_querys['JOIN']} {$this->getWhere()}";
|
||||
$stmt = $this->execute($query);
|
||||
$stmt = $this->execute($this->makeResultQuery("SELECT COUNT({$column})"));
|
||||
$count = $stmt->fetchColumn(0);
|
||||
$this->_reset = true;
|
||||
return $count;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user