$id]; $this->existsInDB = false; if (is_numeric($id) === true && $id > 0 ) { parent::__construct( $table, $filter, null, false ); $this->existsInDB = true; } else { // Create empty skel. parent::__construct($table, null); } } /** * Saves current definition of a Console to database. * * @return mixed Affected rows of false in case of error. * @throws \Exception On error. */ public function save() { if ($this->fields['id'] > 0) { // Update. $updates = $this->fields; $rs = \db_process_sql_update( $this->table, $updates, ['id' => $this->fields['id']] ); if ($rs === false) { global $config; throw new \Exception( __METHOD__.' error: '.$config['dbconnection']->error ); } } else { // Creation. $inserts = $this->fields; // Clean null fields. foreach ($inserts as $k => $v) { if ($v === null) { unset($inserts[$k]); } } $rs = \db_process_sql_insert( $this->table, $inserts ); if ($rs === false) { global $config; throw new \Exception( __METHOD__.' error: '.$config['dbconnection']->error ); } $this->fields['id'] = $rs; } return true; } /** * Remove this Console. * * @return void */ public function delete() { if ($this->existsInDB === true) { \db_process_delete_temp( $this->table, 'id', $this->fields['id'] ); } } }