Optimized Models queries
This commit is contained in:
parent
86dc860290
commit
303075c495
2 changed files with 29 additions and 22 deletions
|
@ -1,12 +1,16 @@
|
|||
<?php
|
||||
|
||||
class Model {
|
||||
|
||||
protected static $db = null;
|
||||
private static $column;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->initDatabase();
|
||||
}
|
||||
public static function initDatabase(){
|
||||
if(!Model::$db){
|
||||
try {
|
||||
/*
|
||||
* Init connection to the DB
|
||||
|
@ -17,6 +21,7 @@ class Model {
|
|||
var_dump($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* GET/SELECT Query
|
||||
*/
|
||||
|
@ -52,14 +57,18 @@ class Model {
|
|||
}
|
||||
protected function getColumns(): array
|
||||
{
|
||||
if(!isset(get_called_class()::$column[get_called_class()])) {
|
||||
get_called_class()::$column[get_called_class()] = [];
|
||||
$q = Model::$db->prepare('SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?');
|
||||
$q->execute(array(get_called_class()));
|
||||
$d = $q->fetchAll(PDO::FETCH_ASSOC);
|
||||
$out = [];
|
||||
forEach($d as $col){
|
||||
foreach ($d as $col) {
|
||||
$out[$col['COLUMN_NAME']] = $col;
|
||||
}
|
||||
return $out;
|
||||
get_called_class()::$column[get_called_class()] = $out;
|
||||
}
|
||||
return get_called_class()::$column[get_called_class()];
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
|
@ -39,11 +39,9 @@ require_once('template/head.php');
|
|||
<label for="typeSelect">Quels services proposez-vous ?</label><br>
|
||||
<?php
|
||||
$c = 0;
|
||||
|
||||
foreach ($services as $service){
|
||||
$c++;
|
||||
?>
|
||||
<div class="form-check form-check-inline">
|
||||
?><div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="checkbox" id="inlineCheckbox<?=$c?>" value="<?=htmlspecialchars($service->getName())?>">
|
||||
<label class="form-check-label" for="inlineCheckbox<?=$c?>"><?=htmlspecialchars($service->getName())?></label>
|
||||
</div>
|
||||
|
|
Reference in a new issue