params_hash[$key] = $value; } //since PHP 5.3 # comments produce nosi //$this->params_hash = parse_ini_file($fpath,FALSE); } // construct key-value hash from DB content private function fromDB ($jobid) { $dbassoc = DB::QueryAllResultsAssoc('SELECT `key`,`value` FROM params WHERE jobid = ?(jobid)', $jobid); foreach ( $dbassoc as $keyvalue ) { $this->params_hash[$keyvalue['key']] = $keyvalue['value']; } } public function __construct($fpath_or_id) { if ( is_numeric($fpath_or_id) ) { $this->fromDB($fpath_or_id); } else { $this->fromFile($fpath_or_id); } } // save key-value hash to DB public function save2DB ($jobid) { $v = DB::QueryResultValue('SELECT COUNT(id) FROM jobs WHERE id = ?(jobid)', $jobid); if ( $v != 1) { Logger::Error("No jobid %s found in database. Saving params failed.", $jobid); return FALSE; } $ins_cnt = 0; foreach ( $this->params_hash as $key => $value ) { $ins_cnt += DB::UpdateQuery( "INSERT INTO params (`jobid`, `key`, `value`) " . "VALUES (?(jobid), ?(key), ?(value))", $jobid, $key, $value); Logger::Debug("Inserting %d: %s => %s", $ins_cnt, $key, $value); } return $ins_cnt; } // return value in hash public function getValue ($key) { return $this->params_hash[$key]; } // print hash (mostly for debug purposes) public function printParams () { var_export($this->params_hash); echo("\n"); } } ?>