- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
public function save() {
if (!empty(self::$single)) {
if (isset(self::$single['id'])) {
$id = self::$single['id'];
unset(self::$single['id']);
$arraySetters = [];
foreach (self::$single as $key => $value) {
$arraySetters[] = '`'.$key.'` = \''.$value.'\'';
}
self::$single['id'] = $id;
self::$exec = static::$db->prepare('UPDATE '.self::$table.' SET '.implode(', ', $arraySetters).' WHERE `id` = '.$id.' LIMIT 1');
return self::$exec->execute();
} else {
$arrayKeys = [];
$arrayValues = [];
foreach (self::$single as $key => $value) {
$arrayKeys[] = '`'.$key.'`';
$arrayValues[] = '\''.$value.'\'';
}
self::$exec = static::$db->prepare('INSERT INTO '.self::$table.' ('.implode(', ', $arrayKeys).') VALUES ('.implode(', ', $arrayValues).')');
if ($status = self::$exec->execute()) {
self::$single['id'] = static::$db->lastInsertId();
}
return $status;
}
}
return false;
}