Пример #1
0
 private static function insert(&$set)
 {
     \Core\DB::$db->beginTransaction();
     $PK = \Core\DB::nextPK(static::table(), static::PK());
     $SQL = 'INSERT INTO ' . static::table() . ' ';
     $columns = [static::PK()];
     $params = [':' . static::PK() => $PK];
     foreach ($set as $col => $val) {
         $columns[] = $col;
         $params[':' . $col] = $val;
     }
     $SQL .= '(' . implode(',', $columns) . ') ' . 'VALUES (' . implode(',', array_keys($params)) . ')';
     $sInsert = \Core\DB::$db->prepare($SQL);
     if (!$sInsert->execute($params)) {
         http_response_code(500) && exit('Failed to create object :/');
     }
     $sInsert->closeCursor();
     \Core\DB::$db->commit();
     return $PK;
 }