PHP8 dbase_replace_record

2024-03-30 21:12 更新

(PF5 < 5.3.0、dBASE 5、dBASE 7)

dbase_replace_record — 替換數(shù)據(jù)庫中的記錄

說明

dbase_replace_record(resource $database, array $data, int $number): bool

將數(shù)據(jù)庫中的給定記錄替換為給定數(shù)據(jù)。

參數(shù) 

database

由 dbase_open() 或 dbase_create() 返回的數(shù)據(jù)庫資源。

data

索引數(shù)據(jù)數(shù)組。項目數(shù)必須等于 數(shù)據(jù)庫中的字段數(shù),否則 dbase_replace_record() 將失敗。

注意

如果您為此使用 dbase_get_record() 返回值 參數(shù),記得重置名為 .deleted

number

從 1 到數(shù)據(jù)庫中記錄數(shù)的整數(shù) (由 dbase_numrecords() 返回)。

返回值 

成功時返回 true, 或者在失敗時返回 false。

更新日志 

版本說明
dbase 7.0.0database現(xiàn)在是資源而不是整數(shù)。

示例 

示例 #1 更新數(shù)據(jù)庫中的記錄

<?php

// open in read-write mode
$db = dbase_open('/tmp/test.dbf', 2);

if ($db) {
  // gets the old row
  $row = dbase_get_record_with_names($db, 1);
  
  // remove the 'deleted' entry
  unset($row['deleted']);
  
  // Update the date field with the current timestamp
  $row['date'] = date('Ymd');
  
  // convert the row to an indexed array
  $row = array_values($row);

  // Replace the record
  dbase_replace_record($db, $row, 1);
  dbase_close($db);
}

?>

注釋 

注意:布爾字段生成 int 元素值 ( 或 ) 通過 dbase_get_record() 或 dbase_get_record_with_names() 檢索時。如果他們被寫回去, 這導(dǎo)致值成為 ,所以必須小心 用于正確調(diào)整值。010

參見 

  • dbase_add_record() - 將記錄添加到數(shù)據(jù)庫
  • dbase_delete_record() - 從數(shù)據(jù)庫中刪除記錄


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號