public function alterar($array, $id) { if (dbase_replace_record($this->conexao, $array, $id)) { return true; } else { return false; } }
function _saveDBFData() { unset($this->DBFData["deleted"]); if ($this->recordNumber <= dbase_numrecords($this->DBFFile)) { if (!dbase_replace_record($this->DBFFile, array_values($this->DBFData), $this->recordNumber)) { $this->setError("I wasn't possible to update the information in the DBF file."); } } else { if (!dbase_add_record($this->DBFFile, array_values($this->DBFData))) { $this->setError("I wasn't possible to add the information to the DBF file."); } } }
/** * Helper function to update a specific field value without modifying anything else * It is really important to have a $where_ary because the dbases's index may change * because of either sorting the list in an external application or inserting a new row. * * this will obviously fail if it is opened in read-only mode (stupid jim) * * @param array $where_ary if not empty, the update will not complete unless these values match in the where array */ private static function dbase_update($db, $index, $update_ary, $where_ary = array(), $trim_compare = false) { //echo 'db: '.$db.' updating index '. $index; $row = dbase_get_record_with_names($db, $index); //print_r($where_ary); echo ' whereary <br> row to update:'; print_r($row); echo ' --row to update <br>'; //echo 'row fetched vs where_ary: ';print_r(array_diff_assoc($where_ary, $row)); $matching_where_key_count = 0; //echo 'count: '.count($where_ary); foreach ($where_ary as $wkey => $wvalue) { if (isset($row[$wkey])) { $matching_where_key_count++; if ($trim_compare && trim($row[$wkey]) != trim($wvalue) || !$trim_compare && $row[$wkey] != $wvalue) { //echo 'where value does not match: '.$wkey.' '.$wvalue.' !== '.$row[$wkey]; return false; //where value did not match, therefore return false } } } //echo 'mwkc: "'.$matching_where_key_count.'"'; if ($matching_where_key_count < 2) { return false; //for security purposes force the update to verify at least 2 valid where keys } //the user may want to search for a user who DOES match the where_ary if returned false above unset($row["deleted"]); // drop the field $before_row = $row; //go and update each specific field foreach ($update_ary as $key => $value) { //question: Do we allow deleting of a specific field? if (isset($row[$key])) { $row[$key] = $value; } } // then convert to numeric to store: $rarr = array(); foreach ($row as $i => $vl) { $rarr[] = $vl; } //echo '<br>updating index '.$index.print_r($rarr, true); $replaced = dbase_replace_record($db, $rarr, $index); self::$dbase_update_records[] = array('index' => $index, 'before' => $before_row, 'after' => $row, 'was_replaced' => $replaced); return $replaced; }
public function setDBFInformation($row_array) { $this->_openDBFFile(true); if ($this->dbf) { unset($row_array["deleted"]); if (!dbase_replace_record($this->dbf, array_values($row_array), $this->record_number)) { $this->setError(sprintf(self::UNABLE_TO_WRITE_DBF_FILE, $this->file_name)); } else { $this->dbf_data = $row_array; } } else { $this->setError(sprintf(self::INCORRECT_DBF_FILE, $this->file_name)); } $this->_closeDBFFile(); }
for ($i = 0; $i < $nf; $i++) { echo $rec[$i], "\n"; } dbase_add_record($db, array(date('Ymd'), 'Maxi2222m Topolov', '23', '*****@*****.**', 'T')); echo 'updating a row...'; // gets the old row $row = dbase_get_record_with_names($db, 1); // remove the 'deleted' entry unset($row['deleted']); $row = array(date('Ymd'), 'Maxitom', '23', '*****@*****.**', 'T'); // Update the date field with the current timestamp // $row['name'] = 'Tom'; echo 'row before inserting is: '; print_r($row); // Replace the record dbase_replace_record($db, $row, 1); echo 'trying record num 1: '; $rec = dbase_get_record($db, 1); $nf = dbase_numfields($db); for ($i = 0; $i < $nf; $i++) { echo $rec[$i], "\n"; } echo 'deleting row 2. before deletion: '; $rec = dbase_get_record($db, 2); $nf = dbase_numfields($db); for ($i = 0; $i < $nf; $i++) { echo $rec[$i], "\n"; } echo dbase_delete_record($db, 2); echo 'before db pack'; echo dbase_pack($db);
/** * @inheritdoc */ public function offsetSet($offset, $value) { if ($this->offsetExists($offset)) { dbase_replace_record($this->_dbaseId, $value, $offset + 1); } else { dbase_add_record($this->_dbaseId, $value); } }
private function _saveDBFData() { if (count($this->DBFData) == 0) { return; } unset($this->DBFData['deleted']); if ($this->recordNumber <= dbase_numrecords($this->DBFFile)) { if (!dbase_replace_record($this->DBFFile, array_values($this->DBFData), $this->recordNumber)) { $this->setError('I wasn\'t possible to update the information in the DBF file.'); } } else { if (!dbase_add_record($this->DBFFile, array_values($this->DBFData))) { $this->setError('I wasn\'t possible to add the information to the DBF file.'); } } }