定制 chvila/php-xbase 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chvila/php-xbase

Composer 安装命令:

composer require chvila/php-xbase

包简介

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

README 文档

README

A simple library for dealing with dbf databases like dBase and FoxPro. It's a port of PHPXbase class written by Erwin Kooi, updated to a PSR-2 compliant code and tweaked for performance and to solve some issues the original code had.

Installation

You can install it through Composer:

$ composer require hisamu/php-xbase

Sample usage

<?php

use XBase\Table;

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

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

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

$table = new Table(dirname(__FILE__).'/test.dbf', null, '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

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');
}

Writing Data

To open a table for writing, you have to use a WritableTable object, as on this example:

<?php

use XBase\WritableTable;

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

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

# optional
$table->close();

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.

统计信息

  • 总下载量: 2.43k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 85
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固