trying to resolve conflict

This commit is contained in:
Malte Schulze Hobeling 2023-01-18 08:39:45 +01:00
parent 2860a01cf8
commit fbfeeb7679

View File

@ -44,18 +44,17 @@ class BancaDati {
$value = ""; $value = "";
$column = ""; $column = "";
foreach ($values as $col => $v){ foreach ($values as $col => $v){
$value .= "'" . $v . "'" . ","; $value .= $v . ",";
$column .= $col . ","; $column .= $col . ",";
} }
$value = trim($value, ","); $value = trim($value, ",");
$column = trim($column, ","); $column = trim($column, ",");
$sql = "INSERT INTO $table ($column) VALUES ($value);"; $sql = "INSERT INTO $table($column) VALUES ($value);";
try { try {
$sth = $this->pdo->prepare($sql); $sth = $this->pdo->prepare($sql);
$sth->execute(); $sth->execute();
}catch (PDOException $e){ }catch (PDOException $e){
var_dump($e);
die; die;
} }
} }
@ -71,7 +70,7 @@ class BancaDati {
public function update(string $table, string $id, array $values){ public function update(string $table, string $id, array $values){
$value = ""; $value = "";
foreach ($values as $col => $v){ foreach ($values as $col => $v){
$value .= $col . "=" . "'" . $v . "'" . ","; $value .= $col . "=" . $v . ",";
} }
$value = trim($value, ","); $value = trim($value, ",");
@ -101,16 +100,23 @@ class BancaDati {
} }
} }
/**
public function select(string $table, array $data, array $order = null){ * einheitliche Select Funktion
$where = ""; * @param string $table
foreach ($data as $col => $v) { * @param array $where ["column"]=>"value" es wird mit LIKE verglichen und mit AND verbunden
if($where != ""){ * @param array|null $order ["by"]=>"column"; ["order"]=>"ASC|DESC"
$where .= " AND "; * @return void
* @author Malte Schulze Hobeling
*/
public function select(string $table, array $where, array $order = null){
$whereString = "";
foreach ($where as $col => $v) {
if($whereString != ""){
$whereString .= " AND ";
} }
$where .= $col . "=" . "'" . $v . "'"; $whereString .= $col . " LIKE " . $v;
} }
$sql = "SELECT * FROM ".$table." WHERE ".$where; $sql = "SELECT * FROM ".$table." WHERE ".$whereString;
if(isset($order["by"])){ if(isset($order["by"])){
$sql .= " ORDER BY ".$order["by"]; $sql .= " ORDER BY ".$order["by"];
} }
@ -118,9 +124,8 @@ class BancaDati {
$sql .= $order["order"]; $sql .= $order["order"];
} }
try { try {
return $this->pdo->query($sql)->fetch(); return $this->pdo->query($sql);
}catch (PDOException $e){ }catch (PDOException $e){
var_dump($e);
die; die;
} }
} }