PHPackages                             totalcrm/php-dbf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. totalcrm/php-dbf

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

totalcrm/php-dbf
================

A simple parser for \*.dbf files using PHP

1.0.5(4y ago)1023.6k↓33.3%2[1 issues](https://github.com/totalcrm/php-dbf/issues)MITPHPPHP &gt;=7.4

Since Dec 2Pushed 4y ago2 watchersCompare

[ Source](https://github.com/totalcrm/php-dbf)[ Packagist](https://packagist.org/packages/totalcrm/php-dbf)[ Docs](https://github.com/totalcrm/php-dbf)[ RSS](/packages/totalcrm-php-dbf/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)Dependencies (1)Versions (5)Used By (0)

PHP DBase
=========

[](#php-dbase)

A simple library for dealing with **dbf** databases like dBase and FoxPro. It's a port of PHPXbase class written by [Erwin Kooi](http://www.phpclasses.org/package/2673-PHP-Access-dbf-foxpro-files-without-PHP-ext-.html), updated to a PSR-2 compliant code and tweaked for performance and to solve some issues the original code had.

Installation
------------

[](#installation)

You can install it through [Composer](https://getcomposer.org):

```
$ composer require totalcrm/php-dbf
```

Sample usage
------------

[](#sample-usage)

More samples in `examle` folder.

### Reading data

[](#reading-data)

```
use TotalCRM\DBase\TableReader;

$table = new TableReader('test.dbf');

while ($record = $table->nextRecord()) {
    echo $record->get('my_column');
    //or
    echo $record->my_column;
}
```

If the data in DB is not in UTF-8 you can specify a charset to convert the data from:

```
use TotalCRM\DBase\TableReader;

$table = new TableReader(
    'test.dbf',
    [
        'encoding' => 'cp1251'
    ]
);
```

It is also possible to read Memos from dedicated files. Just make sure that *.fpt* file with the same name as main database exists.

#### Performance

[](#performance)

You can pass an array of the columns that you need to the constructor, then if your table has columns that you don't use they will not be loaded. This way the parser can run a lot faster.

```
use TotalCRM\DBase\TableReader;

$table = new TableReader(
    'test.dbf',
    [
        'columns' => ['my_column', 'another_column']
    ]
);

while ($record = $table->nextRecord()) {
    echo $record->my_column;
    echo $record->another_column;
}
```

If you know the column type already, you can also call the type-specific function for that field, which increases the speed too.

```
while ($record = $table->nextRecord()) {
    echo $record->get('my_column');
    echo $record->get('another_column');
}
```

### Editing Data

[](#editing-data)

To open a table for editing, you have to use a `TableEditor` object, as on this example:

```
use TotalCRM\DBase\TableEditor;

$table = new TableEditor('test.dbf');

for ($i = 0; $i < 10; $i++) {
    $record = $table->nextRecord();

    $record->set('field', 'string');
    //or
    $record->field = 'string';

    $table->writeRecord();
}

$table
    ->save()
    ->close();
```

#### Add new record

[](#add-new-record)

```
use TotalCRM\DBase\TableEditor;

$table = new TableEditor(
    'file.dbf',
    [
        'editMode' => TableEditor::EDIT_MODE_CLONE, //default
    ]
);
$record = $table->appendRecord();
$record->set('name', 'test name');
$record->set('age', 20);

$table
    ->writeRecord()
    ->save()
    ->close();
```

#### Delete record

[](#delete-record)

```
use TotalCRM\DBase\TableEditor;

$table = new TableEditor('file.dbf');

while ($record = $table->nextRecord()) {
    if ($record->get('delete_this_row')) {
        $table->deleteRecord(); //mark record deleted
    }
}

$table
    ->pack() //remove deleted rows
    ->save() //save changes
    ->close();
```

### Creating table

[](#creating-table)

To create a table file you need to use the `TableCreator` object.

```
use TotalCRM\DBase\Enum\FieldType;
use TotalCRM\DBase\Enum\TableType;
use TotalCRM\DBase\Header\Column;
use TotalCRM\DBase\Header\HeaderFactory;
use TotalCRM\DBase\TableCreator;
use TotalCRM\DBase\TableEditor;

// you can specify any other database version from TableType
$header = HeaderFactory::create(TableType::DBASE_III_PLUS_MEMO);
$filepath = '/path/to/new/file.dbf';

$tableCreator = new TableCreator($filepath, $header);
$tableCreator
    ->addColumn(new Column([
        'name'   => 'name',
        'type'   => FieldType::CHAR,
        'length' => 20,
    ]))
    ->addColumn(new Column([
        'name'   => 'birthday',
        'type'   => FieldType::DATE,
    ]))
    ->addColumn(new Column([
        'name'   => 'is_man',
        'type'   => FieldType::LOGICAL,
    ]))
    ->addColumn(new Column([
        'name'   => 'bio',
        'type'   => FieldType::MEMO,
    ]))
    ->addColumn(new Column([
        'name'         => 'money',
        'type'         => FieldType::NUMERIC,
        'length'       => 20,
        'decimalCount' => 4,
    ]))
    ->addColumn(new Column([
        'name'   => 'image',
        'type'   => FieldType::MEMO,
    ]))
    ->save(); //creates file

$table = new TableEditor($filepath);
//... add records
```

Troubleshooting
---------------

[](#troubleshooting)

I'm not an expert on dBase and I don't know all the specifics of the field types and versions, so the lib may not be able to handle some situations. If you find an error, please open an issue and send me a sample table that I can reproduce your problem, and I'll try to help.

Useful links
------------

[](#useful-links)

[Xbase File Format Description](http://www.manmrk.net/tutorials/database/xbase/)

[File Structure for dBASE 7](http://www.dbase.com/KnowledgeBase/int/db7_file_fmt.htm)

[DBF AND DBT/FPT FILE STRUCTURE](http://www.independent-software.com/dbase-dbf-dbt-file-format.html)

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

1629d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15926848?v=4)[TotalCRM](/maintainers/TotalCRM)[@totalcrm](https://github.com/totalcrm)

---

Top Contributors

[![totalcrm](https://avatars.githubusercontent.com/u/15926848?v=4)](https://github.com/totalcrm "totalcrm (7 commits)")

---

Tags

dbasefoxprofoxpro-dbf-filesphpphp-librarytotalcrmphpdbfdbase

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/totalcrm-php-dbf/health.svg)

```
[![Health](https://phpackages.com/badges/totalcrm-php-dbf/health.svg)](https://phpackages.com/packages/totalcrm-php-dbf)
```

###  Alternatives

[hisamu/php-xbase

A simple parser for \*.dbf, \*.fpt files using PHP

1871.5M2](/packages/hisamu-php-xbase)[nikic/phlexy

Lexing experiments in PHP

162570.9k13](/packages/nikic-phlexy)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23483.5k2](/packages/corveda-php-sandbox)[blancks/fast-jsonpatch-php

Class designed to efficiently handle JSON Patch operations in accordance with the RFC 6902 specification

396.4k](/packages/blancks-fast-jsonpatch-php)[bupy7/xml-constructor

The array-like constructor of XML document structure.

1337.9k](/packages/bupy7-xml-constructor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
