PHP: dBase Functions - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

dbase_add_record dba_sync

Last updated: Fri, 26 Jan 2007

view this page in

# XXV. dBase Functions

# Введение

These functions allow you to access records stored in dBase-format (dbf) databases.

dBase files are simple sequential files of fixed length records. Records are appended to the end of the file and delete records are kept until you call dbase_pack().

The types of dBase fields available are:

Таблица 1. Available types of fields

Field | dBase Type | Format | Additional information
--- | --- | --- | ---
`M` | Memo | n/a | This type is not supported by PHP, such field will be ignored
`D` | Date | `YYYYMMDD` | The field length is limited to 8
`N` | Number | A number | You must declare a length and a precision (the number of digits after the decimal point)
`C` | String | A string | You must declare a length. When retrieving data, the string will be right-padded with spaces to fit the declared length.
`L` | Boolean | `T` or `Y` for `TRUE`, `F` or `N` for `FALSE` | Stored and returned as an integer (1 or 0)
`F` | Float | A float number | Support for this type of field was added in PHP 5.2.0

Внимание
There is no support for indexes or memo fields. There is no support for locking, too. Two concurrent webserver processes modifying the same dBase file will very likely ruin your database. We recommend that you do not use dBase files as your production database. Choose any real SQL server instead; MySQL or Postgres are common choices with PHP. dBase support is here to allow you to import and export data to and from your web database, because the file format is commonly understood by Windows spreadsheets and organizers.

# Установка

In order to enable the bundled dbase library and to use these functions, you must compile PHP with the `--enable-dbase` option.

# Настройка во время выполнения

Данное расширение не определяет никакие директивы конфигурации в `php.ini`.

# Типы ресурсов

Данное расширение не определяет никакие типы ресурсов.

# Примеры

Many examples in this reference require a dBase database. We will use `/tmp/test.dbf` that will be created in the example of dbase_create().

# Предопределенные константы

Данное расширение не определяет никакие константы.

add a note User Contributed Notes
dBase Functions
Hadi Rusiah / deegos at yahoo dot com
08-May-2004 10:33
`If you are using PHP < 5, you can use this function to retrieve dbf header
<?
function get_dbf_header($dbfname) {
$fdbf = fopen($dbfname,'r');
$dbfhdrarr = array();
$buff32 = array();
$i = 1;
$goon = true;
while ($goon) {
if (!feof($fdbf)) {
$buff32 = fread($fdbf,32);
if ($i > 1) {
if (substr($buff32,0,1) == chr(13)) {
$goon = false;
} else {
$pos = strpos(substr($buff32,0,10),chr(0));
$pos = ($pos == 0?10:$pos);
$fieldname = substr($buff32,0,$pos);
$fieldtype = substr($buff32,11,1);
$fieldlen = ord(substr($buff32,16,1));
$fielddec = ord(substr($buff32,17,1));
array_push($dbfhdrarr, array($fieldname,$fieldtype,$fieldlen,$fielddec));
}
}
$i++;
} else {
$goon = false;
}
}
fclose($fdbf);
return($dbfhdrarr);
}
$arr = get_dbf_header('/data/file.dbf');
print_r($arr);
?>`
add a note
dbase_add_record dba_sync

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST