PHPackages                             naril/dbase - 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. [Database &amp; ORM](/categories/database)
4. /
5. naril/dbase

ActiveLibrary[Database &amp; ORM](/categories/database)

naril/dbase
===========

Library to access dbase / xbase / dbf database files

1.1.5(8y ago)0297↓100%MITPHPPHP &gt;=5.3

Since Aug 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/naril/dbase)[ Packagist](https://packagist.org/packages/naril/dbase)[ Docs](https://github.com/majkel89)[ RSS](/packages/naril-dbase/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (10)Used By (0)

dbase
=====

[](#dbase)

[![Build Status](https://camo.githubusercontent.com/b44dec7e335f8464452c613a2692f636338c6477815b9874fcc0ef996189f7f3/68747470733a2f2f7472617669732d63692e6f72672f6d616a6b656c38392f64626173652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/majkel89/dbase)[![SensioLabsInsight](https://camo.githubusercontent.com/da30bc52b25a5221c6d6f8dea6ff489b3890322a6c00f7ee52577b58ea4b1e18/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f31626263303862362d313261342d346161352d393930382d6162623236383465326334352f6d696e692e706e67)](https://insight.sensiolabs.com/projects/1bbc08b6-12a4-4aa5-9908-abb2684e2c45)[![Latest Stable Version](https://camo.githubusercontent.com/7b8c6f26aad29da692fa032cc2a713a94e8178b161bd46f97c4078cbfa6dd075/68747470733a2f2f706f7365722e707567782e6f72672f6f72672e6d616a6b656c2f64626173652f762f737461626c65)](https://packagist.org/packages/org.majkel/dbase)[![Total Downloads](https://camo.githubusercontent.com/2c3bcd180314676f96c785a5f2acf23f2d3a5f4aead995385db1324f00dbd3dc/68747470733a2f2f706f7365722e707567782e6f72672f6f72672e6d616a6b656c2f64626173652f646f776e6c6f616473)](https://packagist.org/packages/org.majkel/dbase)[![Latest Unstable Version](https://camo.githubusercontent.com/c25581e9b499ddb3f80da6c3314a29aee0b5721a206ead2bbb6144c153d0750e/68747470733a2f2f706f7365722e707567782e6f72672f6f72672e6d616a6b656c2f64626173652f762f756e737461626c65)](https://packagist.org/packages/org.majkel/dbase)[![PHP Version](https://camo.githubusercontent.com/3ca7edd1dfd3a02990799e336113188aa5cfd0a61ace5cc1c6246aecff814598/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d504850253230352e332532422d6c69676874677265792e737667)](https://camo.githubusercontent.com/3ca7edd1dfd3a02990799e336113188aa5cfd0a61ace5cc1c6246aecff814598/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f76657273696f6e2d504850253230352e332532422d6c69676874677265792e737667)[![License](https://camo.githubusercontent.com/33f0fc4fa8805a0ef78a821e6405951d735943e47e7ce6a4a247b328b6da53e9/68747470733a2f2f706f7365722e707567782e6f72672f6f72672e6d616a6b656c2f64626173652f6c6963656e7365)](https://packagist.org/packages/org.majkel/dbase)

Library for processing dbase tables.

Table of Contents
-----------------

[](#table-of-contents)

1. [Supported formats](#supported-formats)
    1. [Supported memo formats](#supported-memo-formats)
2. [Installation](#installation)
3. [Documentation](#documentation)
    1. [Reading tables](#reading-tables)
    2. [Inserting rows](#inserting-rows)
    3. [Automatic type conversion](#automatic-type-conversion)
    4. [Record object](#record-object)
        1. [Reading data from record](#reading-data-from-record)
        2. [Writing data to record](#writing-data-to-record)
    5. [Record object](#record-object)
    6. [Updating tables](#updating-tables)
    7. [Deleting records](#deleting-records)
    8. [Transactions](#transactions)
    9. [Defining tables](#defining-tables)
        1. [Creating table from another table](#creating-table-from-another-table)
    10. [Filters](#filters)
        1. [Using filters](#using-filters)
        2. [Writing custom filter](#writing-custom-filter)

Supported formats
-----------------

[](#supported-formats)

- dBASE III
- dBASE III PLUS

##### Supported memo formats

[](#supported-memo-formats)

- DBT
- FPT

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

[](#installation)

### Composer

[](#composer)

Using composer to install this library is strongly recommended.

```
composer require org.majkel/dbase

```

Then in your script use this line of code

```
require_once 'vendor/autoload.php'
```

### Old-fashion style

[](#old-fashion-style)

Download library and place it somewhere on disk.

Then in your script use this line of code

```
require_once 'DBASE/LIB/DIR/autoloader.php';
```

Documentation
-------------

[](#documentation)

### Reading tables

[](#reading-tables)

Table object is both array accessible and traversable. You can loop over it as collection or read specific record by it's index.

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;

$totalSum = 0;

$dbf = Table::fromFile('some/table.dbf');

foreach ($dbf as $record) {
    // returns all records includeing deleted ones
    if (!$record->isDeleted()) {
        $totalSum += $record->int_val;
    }
}

echo "Total sum is $totalSum, 5th description: {$record[4]['description']}\n";
```

### Inserting rows

[](#inserting-rows)

You can insert records as record object or as an associative array.

> Note that insert operation is not atomic. Use transactions to achieve integrity safety.

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;
use org\majkel\dbase\Record;

$dbf = Table::fromFile('some/table.dbf');

$record = new Record();
$record->fieldBool = true;
$record->fieldInt  = 123;
$record->fieldChar = 'some text 1';
$record->fieldMemo = 'some long text';

$dbf->insert($record);

$dbf->insert([
    'fieldBool' => false,
    'fieldInt'  => 321,
    'fieldChar' => 'some text 2',
]);

```

### Automatic type conversion

[](#automatic-type-conversion)

Dbase and PHP types are automatically converted during fetching and storing of rows.

Dbase typeType namePossible valuesPHP typeCCharacter*any string*stringDDateDDMMYYDateTimeLLogical\[YTNF?\]booleanMMemo*any string*stringNNumeric\[0-9\]int### Record object

[](#record-object)

Record is basically ArrayObject. Object that can be treated as array.

#### Reading data from record

[](#reading-data-from-record)

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;

$dbf = Table::fromFile('some/table.dbf');

// fetch first record
$record = $dbf[0];

echo "int  field: {$record->number}\n"; // returns integer
echo "bool field: {$record->boolean}\n"; // returns boolean
echo "date field: {$record->date->format('Y-m-d')}\n"; // return DateTime object
echo "text field: {$record->text}\n"; // returns string
echo "memo field: {$record->memo}\n"; // returns string (not entity id)
echo "memo field id: {$record->getMemoEntryId('memo')}\n"; // returns entity id for memo field `memo`
echo "is record deleted: {$record->isDeleted('memo')}\n"; // returns whether record is deleted

// ... or ...

echo "int  field: {$record['number']}\n"; // returns integer
echo "bool field: {$record['boolean']}\n"; // returns boolean
echo "date field: {$record['date']->format('Y-m-d')}\n"; // return DateTime object
echo "text field: {$record['text']}\n"; // returns string
echo "memo field: {$record['memo']}\n"; // returns string (not entity id)
echo "memo field id: {$record->getMemoEntryId('memo')}\n"; // returns entity id for memo field `memo`
echo "is record deleted: {$record->isDeleted('memo')}\n"; // returns whether record is deleted

// you can loop over fields in the record
foreach ($record as $fieldName => $fieldValue) {
    echo "$fieldName = $fieldValue\n";
}
```

#### Writing data to record

[](#writing-data-to-record)

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;

$dbf = Table::fromFile('some/table.dbf');

// fetch first record
$record = $dbf[0];

$record->number  = 123;
$record->boolean = true;
$record->date    = new DateTime();
$record->text    = 'some text';
$record->memo    = 'some longer text';

// ... or ...

$record['number']  = 123;
$record['boolean'] = true;
$record['date']    = new DateTime();
$record['text']    = 'some text';
$record['memo']    = 'some longer text';
```

Updating tables
---------------

[](#updating-tables)

> Note that update operation is not atomic. Use transactions to achieve integrity safety.

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;

$dbf = Table::fromFile('some/table.dbf');

foreach ($dbf as $record) {
    $record->int_val += 10;
    $dbf->update($record); // header is updated everytime
}
```

Deleting records
----------------

[](#deleting-records)

> Do not use `Record::setDeleted` to delete records

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;

$dbf = Table::fromFile('some/table.dbf');

// delete 7th record
$dbf->delete(6);

// undelete 6th record
$dbf->markDelete(5, false);
```

### Transactions

[](#transactions)

Transactions can prevent two processes from updating the same file.

When some process cannot acquire lock on the table exception is being thrown.

Transactions can also save you from unnecessary header updates. Header is updated at the end of transaction.

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Table;

$dbf = Table::fromFile('some/table.dbf');

// header is updated. Transaction flag is set
$dbf->beginTransaction();

foreach ($dbf as $record) {
    $record->int_val += 10;
    $dbf->update($record);  // header is not written
}

// duplicate last row
$dbf->insert($record); // header is not written

// header is written, transaction flag is cleared, recond count is updated
$dbf->endTransaction();
```

### Defining tables

[](#defining-tables)

To construct new table use builder object.

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Builder;
use org\majkel\dbase\Format;
use org\majkel\dbase\Field;

$table = Builder::create()
    ->setFormatType(Format::DBASE3)
    ->addField(Field::create(Field::TYPE_CHARACTER)->setName('str')->setLength(15))
    ->addField(Field::create(Field::TYPE_LOGICAL)->setName('bool'))
    ->addField(Field::create(Field::TYPE_NUMERIC)->setName('num'))
    ->build('destination.dbf');

for ($i = 1; $i insert([
        'str' => "Str $i",
        'bool' => false,
        'num' => $i,
    ]);
}
```

#### Creating table from another table

[](#creating-table-from-another-table)

You can create new table form existing table definition.

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Builder;
use org\majkel\dbase\Format;
use org\majkel\dbase\Field;

$table = Builder::fromFile('source.dbf')
    ->setFormatType(Format::DBASE3)
    ->addField(Field::create(Field::TYPE_NUMERIC)->setName('newField1'))
    ->build('destination.dbf');

for ($i = 1; $i insert([
        'oldField1' => "Str $i",
        'oldField2' => false,
        'newField1' => $i,
    ]);
}

```

### Filters

[](#filters)

Although values are automatically converted based on column type sometimes it is necessary to perform additional processing. To achieve that you can add filters on columns.

#### Using filters

[](#using-filters)

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\Builder;
use org\majkel\dbase\filter\TrimFilter;
use your\CurrencyFilter;

$dbf = Table::fromFile('some/table.dbf');
$dbf->getHeader()->getField('price')
    ->addFilter(new TrimFilter())
    ->addFilter(new CurrencyFilter(',', '.'));

foreach ($dbf as $record) {
    // ...
}
```

Filters are applied during loading in the order they are defined. During serialization filters are applied in reversed order.

#### Writing custom filter

[](#writing-custom-filter)

```
require_once 'vendor/autoload.php'

use org\majkel\dbase\FilterInterface;
use org\majkel\dbase\Field;

class CurrencyFilter extends FilterInterface
{
    /** @var string */
    private $inputDot;
    /** @var string */
    private $outputDot;

    /**
     * @param string $inputDot
     * @param string $outputDot
     */
    public function __construct($inputDot, $outputDot)
    {
        $this->inputDot = $inputDot;
        $this->outputDot = $outputDot;
    }

    /**
     * From table value to PHP value
     *
     * @param mixed $value
     * @return mixed
     */
    public function toValue($value)
    {
        return str_replace($this->inputDot, $this->outputDot, $value);
    }

    /**
     * From PHP value to table value
     *
     * @param mixed $value
     * @return mixed
     */
    public function fromValue($value)
    {
        return str_replace($this->outputDot, $this->inputDot, $value);
    }

    /**
     * Filter can be applied on string like columns
     *
     * @param integer $type
     * @return boolean
     */
    public function supportsType($type)
    {
        return in_aray($type, [Field::TYPE_CHARACTER, Field::TYPE_MEMO]);
    }
}
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~45 days

Total

9

Last Release

3204d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/06627e9f9243a622a6d7ce8389d7bdb0f5b35bfce1d72e2ba196744b55b2bdcd?d=identicon)[naril](/maintainers/naril)

---

Top Contributors

[![majkel89](https://avatars.githubusercontent.com/u/1094964?v=4)](https://github.com/majkel89 "majkel89 (132 commits)")

---

Tags

dbfdbasexbase

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/naril-dbase/health.svg)

```
[![Health](https://phpackages.com/badges/naril-dbase/health.svg)](https://phpackages.com/packages/naril-dbase)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[mongodb/mongodb

MongoDB driver library

1.6k64.0M543](/packages/mongodb-mongodb)[org.majkel/dbase

Library to access dbase / xbase / dbf database files

33100.7k1](/packages/orgmajkel-dbase)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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