add: select

This commit is contained in:
Malte Schulze Hobeling 2023-01-11 14:40:12 +01:00
parent 143874af78
commit 84bf6b2d36

View File

@ -100,25 +100,26 @@ class BancaDati {
}
}
/**
* Einheitliche select Funktion
* @param string $table
* @param array $selects
* @param array $data
* @return void
* @author Malte Schulze Hobeling
*/
public function select(string $table, array $selects, array $data){
$view = "";
foreach ($selects as $select){
$view .= $select . ",";
}
$view = trim($view,",");
public function select(string $table, array $data, array $order = null){
$where = "";
foreach ($data as $col => $v) {
$where .= $col . "=" . $v . " AND ";
if($where != ""){
$where .= " AND ";
}
$where .= $col . "=" . $v;
}
$sql = "SELECT * FROM ".$table." WHERE ".$where;
if(isset($order["by"])){
$sql .= " ORDER BY ".$order;
}
if(isset($order["order"])){
$sql .= $order["order"];
}
try {
return $this->pdo->query($sql);
}catch (PDOException $e){
die;
}
$where = trim($where,"AND ");
$sql = "SELECT ".$view." FROM ".$table." WHERE ".$where.";";
}
}