better select

This commit is contained in:
Malte Schulze Hobeling 2023-01-18 10:51:28 +01:00
parent b93e0c8e5a
commit e666991b60

View File

@ -102,27 +102,30 @@ class BancaDati {
/**
* einheitliche Select Funktion
* kann sortiert werden durch ["by"]=>"col" und ["order"]=>"ASC|DESC"
* @param string $table
* @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden
* @param array|null $order ["by"]=>"column"; ["order"]=>"ASC|DESC"
* @return void
* @author Malte Schulze Hobeling
*/
public function select(string $table, array $where, array $order = null){
public function select(string $table, array $where){
$whereString = "";
$orderString = "";
if(isset($where["by"])){
$orderString = " ORDER BY " . $where["by"];
unset($where["by"]);
if(isset($where["order"])){
$orderString .= " " . $where["order"];
unset($where["order"]);
}
}
foreach ($where as $col => $v) {
if($whereString != ""){
$whereString .= " AND ";
}
$whereString .= "`" . $col . "` LIKE '" . $v . "'";
}
$sql = "SELECT * FROM ".$table." WHERE ".$whereString.";";
if(isset($order["by"])){
$sql .= " ORDER BY ".$order["by"];
}
if(isset($order["order"])){
$sql .= $order["order"];
}
$sql = "SELECT * FROM ".$table." WHERE ".$whereString.$orderString.";";
try {
return $this->pdo->query($sql)->fetch();
}catch (PDOException $e){