naderskhan / php-xbase

A simple parser for *.dbf files using PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP XBase

A simple parser for *.dbf (dBase, foxpro). It's a port of PHPXbase class written by Erwin Kooi, updated to a 5.3 / PSR compliant code.

Sample code:

<?php

use XBase\Table;

$table = new Table(dirname(__FILE__).'/test.dbf');

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

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.

<?php

use XBase\Table;

$table = new Table(dirname(__FILE__).'/test.dbf', array('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->getChar('my_column');
    echo $record->getDate('another_column');
}

Write Data

<?php

use XBase\Table;

$table = new Table(dirname(__FILE__).'/test.dbf'));
$table->openWrite();

for ($i = 0; $i < 10; $i++) {
    $record = $table->nextRecord();
    $record->field = 'string';
    $table->writeRecord();
}

# optional
$table->close();

About

A simple parser for *.dbf files using PHP


Languages

Language:PHP 100.0%