PHPackages                             hisamu/php-xbase - 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. hisamu/php-xbase

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

hisamu/php-xbase
================

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

2.4.0(3mo ago)1871.5M—6.1%86[7 issues](https://github.com/luads/php-xbase/issues)[3 PRs](https://github.com/luads/php-xbase/pulls)2MITPHPPHP &gt;=7.1CI passing

Since Apr 13Pushed 3mo ago16 watchersCompare

[ Source](https://github.com/luads/php-xbase)[ Packagist](https://packagist.org/packages/hisamu/php-xbase)[ Docs](https://github.com/luads/php-xbase)[ RSS](/packages/hisamu-php-xbase/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (30)Used By (2)

PHP XBase
=========

[](#php-xbase)

[![Build Status](https://camo.githubusercontent.com/6eb4b3a674749309ffd79a6fe3faf2979a0f9976362bde89193782e1de8513e6/68747470733a2f2f7472617669732d63692e6f72672f6c756164732f7068702d78626173652e7376673f6272616e63683d6d617374657226743d323032303033313731373233)](https://travis-ci.org/luads/php-xbase)[![Test Coverage](https://camo.githubusercontent.com/a31fc6f4bb3a866e19893d4ea71e16388e3e33128480edb929b2d56d4164c265/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61336466366361353139623463656539386336642f746573745f636f766572616765)](https://codeclimate.com/github/hisamu/php-xbase/test_coverage)[![Latest Stable Version](https://camo.githubusercontent.com/f64967c2dd0866abf24639b496758964b376ba50e6737365d6a5e03ce7f71f86/68747470733a2f2f706f7365722e707567782e6f72672f686973616d752f7068702d78626173652f762f737461626c65)](https://packagist.org/packages/hisamu/php-xbase)[![Total Downloads](https://camo.githubusercontent.com/42f9bb38b62048f58584e56eadafd9b5edd636cc03ff9fbd8a50378ab68e6571/68747470733a2f2f706f7365722e707567782e6f72672f686973616d752f7068702d78626173652f646f776e6c6f616473)](https://packagist.org/packages/hisamu/php-xbase)[![License](https://camo.githubusercontent.com/f88ddb5a8e1ce28ea2b14c81248d21eb2e9ba91adcd0e52c3c3a784f7c7bc6e7/68747470733a2f2f706f7365722e707567782e6f72672f686973616d752f7068702d78626173652f6c6963656e7365)](https://packagist.org/packages/hisamu/php-xbase)

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 hisamu/php-xbase
```

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

[](#sample-usage)

More samples in `tests` folder.

### Reading data

[](#reading-data)

```
use XBase\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 XBase\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 XBase\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 XBase\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 XBase\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 XBase\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 XBase\Enum\FieldType;
use XBase\Enum\TableType;
use XBase\Header\Column;
use XBase\Header\HeaderFactory;
use XBase\TableCreator;
use XBase\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

63

—

FairBetter than 99% of packages

Maintenance79

Regular maintenance activity

Popularity59

Moderate usage in the ecosystem

Community35

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 68.8% 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 ~128 days

Recently: every ~335 days

Total

29

Last Release

103d ago

Major Versions

1.4.0 → 2.0.02021-03-21

1.4.1 → 2.1.22022-06-04

PHP version history (2 changes)1.0.0PHP &gt;=5.3.0

1.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4e4cca3181b907f212a394d38d02712caecbbbd327277aedd8b208929ab99f2?d=identicon)[lsouza](/maintainers/lsouza)

![](https://avatars.githubusercontent.com/u/3841197?v=4)[Alexander Strizhak](/maintainers/gam6itko)[@gam6itko](https://github.com/gam6itko)

---

Top Contributors

[![gam6itko](https://avatars.githubusercontent.com/u/3841197?v=4)](https://github.com/gam6itko "gam6itko (137 commits)")[![luads](https://avatars.githubusercontent.com/u/194708?v=4)](https://github.com/luads "luads (28 commits)")[![gerryd](https://avatars.githubusercontent.com/u/3003371?v=4)](https://github.com/gerryd "gerryd (4 commits)")[![xmorave2](https://avatars.githubusercontent.com/u/1775826?v=4)](https://github.com/xmorave2 "xmorave2 (3 commits)")[![louisroy](https://avatars.githubusercontent.com/u/201383?v=4)](https://github.com/louisroy "louisroy (3 commits)")[![josev814](https://avatars.githubusercontent.com/u/12461921?v=4)](https://github.com/josev814 "josev814 (2 commits)")[![CDyWeb](https://avatars.githubusercontent.com/u/2254938?v=4)](https://github.com/CDyWeb "CDyWeb (2 commits)")[![aaronhuisinga](https://avatars.githubusercontent.com/u/2423844?v=4)](https://github.com/aaronhuisinga "aaronhuisinga (2 commits)")[![kovinet](https://avatars.githubusercontent.com/u/707846?v=4)](https://github.com/kovinet "kovinet (2 commits)")[![panel-sk](https://avatars.githubusercontent.com/u/6382700?v=4)](https://github.com/panel-sk "panel-sk (2 commits)")[![s-chizhik](https://avatars.githubusercontent.com/u/5587936?v=4)](https://github.com/s-chizhik "s-chizhik (2 commits)")[![risingphoenix](https://avatars.githubusercontent.com/u/2676148?v=4)](https://github.com/risingphoenix "risingphoenix (1 commits)")[![angelhappyboy](https://avatars.githubusercontent.com/u/26516525?v=4)](https://github.com/angelhappyboy "angelhappyboy (1 commits)")[![developer88](https://avatars.githubusercontent.com/u/583275?v=4)](https://github.com/developer88 "developer88 (1 commits)")[![cuchac](https://avatars.githubusercontent.com/u/165461?v=4)](https://github.com/cuchac "cuchac (1 commits)")[![martonmiklos](https://avatars.githubusercontent.com/u/1609182?v=4)](https://github.com/martonmiklos "martonmiklos (1 commits)")[![naderesk](https://avatars.githubusercontent.com/u/5327393?v=4)](https://github.com/naderesk "naderesk (1 commits)")[![spdionis](https://avatars.githubusercontent.com/u/4737101?v=4)](https://github.com/spdionis "spdionis (1 commits)")[![retnek](https://avatars.githubusercontent.com/u/1765261?v=4)](https://github.com/retnek "retnek (1 commits)")[![ebta](https://avatars.githubusercontent.com/u/1849004?v=4)](https://github.com/ebta "ebta (1 commits)")

---

Tags

dbfdbasefoxpro

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/hisamu-php-xbase/health.svg)

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

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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