add: insert into

This commit is contained in:
Don Bock 2022-12-21 11:19:40 +01:00
parent a568d36eb2
commit 6dffa09e88

View File

@ -29,6 +29,41 @@ class BancaDati {
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
/**
* Einheitliche Insert Funktion
* @param string $table
* @param array $values
* @return void
* author Simon Bock
*/
public function insert(string $table, array $values){
$value = "";
$column = "";
foreach ($values as $col => $v){
$value .= $v . ",";
$column .= $col . ",";
}
$value = trim($value, ",");
$column = trim($column, ",");
$sql = "INSERT INTO $table($column) VALUES ($value);";
try {
$sth = $this->pdo->prepare($sql);
$sth->execute();
}catch (\PDOException $e){
die;
}
}
/**
* Einheitliche Update Funktion
* @param string $table
* @param string $id
* @param array $values
* @return void
* @author Malte Schulze Hobeling
*/
public function update(string $table, string $id, array $values){
$value = "";
foreach ($values as $col => $v){
@ -44,4 +79,21 @@ class BancaDati {
die;
}
}
/**
* Einheitliche Delete Funktion
* @param string $table
* @param string $id
* @return void
* @author Malte Schulze Hobeling
*/
public function delete(string $table, string $id){
$sql = "DELETE FROM " . $table . " WHERE `id` = " . $id . ";";
try {
$sth = $this->pdo->prepare($sql);
$sth->execute();
}catch (\PDOException $e){
die;
}
}
}