add: select
This commit is contained in:
parent
143874af78
commit
84bf6b2d36
@ -100,25 +100,26 @@ class BancaDati {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Einheitliche select Funktion
|
public function select(string $table, array $data, array $order = null){
|
||||||
* @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,",");
|
|
||||||
$where = "";
|
$where = "";
|
||||||
foreach ($data as $col => $v) {
|
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.";";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user