PHP8 dbase_replace_record

2024-03-30 21:12 更新

(PF5 < 5.3.0、dBASE 5、dBASE 7)

dbase_replace_record — 替换数据库中的记录

说明

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

将数据库中的给定记录替换为给定数据。

参数 

database

由 dbase_open() 或 dbase_create() 返回的数据库资源。

data

索引数据数组。项目数必须等于 数据库中的字段数,否则 dbase_replace_record() 将失败。

注意

如果您为此使用 dbase_get_record() 返回值 参数,记得重置名为 .deleted

number

从 1 到数据库中记录数的整数 (由 dbase_numrecords() 返回)。

返回值 

成功时返回 true, 或者在失败时返回 false。

更新日志 

版本说明
dbase 7.0.0database现在是资源而不是整数。

示例 

示例 #1 更新数据库中的记录

<?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() 检索时。如果他们被写回去, 这导致值成为 ,所以必须小心 用于正确调整值。010

参见 

  • dbase_add_record() - 将记录添加到数据库
  • dbase_delete_record() - 从数据库中删除记录


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号