0% found this document useful (0 votes)
7 views

PHP_ dBase Functions - Manual

Uploaded by

RachelPhillips
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

PHP_ dBase Functions - Manual

Uploaded by

RachelPhillips
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

12/8/24, 11:46 AM PHP: dBase Functions - Manual

Downloads
Documentation
Get Involved
Help

Search docs
phpday 2025 - Call For Papers

Getting Started
Introduction
A simple tutorial
Language Reference
Basic syntax
Types
Variables
Constants
Expressions
Operators
Control Structures
Functions
Classes and Objects
Namespaces
Enumerations
Errors
Exceptions
Fibers
Generators
Attributes
References Explained
Predefined Variables
Predefined Exceptions
Predefined Interfaces and Classes
Predefined Attributes
Context options and parameters

https://www.php.net/manual/en/ref.dbase.php 1/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

Supported Protocols and Wrappers

Security
Introduction
General considerations
Installed as CGI binary
Installed as an Apache module
Session Security
Filesystem Security
Database Security
Error Reporting
User Submitted Data
Hiding PHP
Keeping Current
Features
HTTP authentication with PHP
Cookies
Sessions
Handling file uploads
Using remote files
Connection handling
Persistent Database Connections
Command line usage
Garbage Collection
DTrace Dynamic Tracing

Function Reference
Affecting PHP's Behaviour
Audio Formats Manipulation
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing

https://www.php.net/manual/en/ref.dbase.php 2/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

Variable and Type Related Extensions


Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions

Keyboard Shortcuts
?
This help
j
Next menu item
k
Previous menu item
gp
Previous man page
gn
Next man page
G
Scroll to bottom
gg
Scroll to top
gh
Goto homepage
gs
Goto search
(current page)
/
Focus search box

dbase_add_record »
« Predefined Constants

PHP Manual
Function Reference
Database Extensions
Vendor Specific Database Extensions
dBase

Change language: English

dBase Functions ¶
Examples ¶

https://www.php.net/manual/en/ref.dbase.php 3/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

Many examples in this reference require a dBase database. We will use /tmp/test.dbf that will
be created in the example of dbase_create().

Table of Contents ¶
dbase_add_record — Adds a record to a database
dbase_close — Closes a database
dbase_create — Creates a database
dbase_delete_record — Deletes a record from a database
dbase_get_header_info — Gets the header info of a database
dbase_get_record — Gets a record from a database as an indexed array
dbase_get_record_with_names — Gets a record from a database as an associative array
dbase_numfields — Gets the number of fields of a database
dbase_numrecords — Gets the number of records in a database
dbase_open — Opens a database
dbase_pack — Packs a database
dbase_replace_record — Replaces a record in a database

Found A Problem?
Learn How To Improve This Page • Submit a Pull Request • Report a Bug
+add a note

User Contributed Notes 2 notes

up
down
9
bi.idan AT gmail.com ¶
17 years ago
I know lots of you dosent really use dbase, but i've builded a class to help
the one how dose.
(sorry for bad english)

- dbase.php

<?php

set_time_limit (0);
// site_path defined by parent
require_once (SITE_PATH. '/server/php/libs/dbase/handler.php');

/* DBase (dbf)
* manage dbf files, exports and search functionality
* with buildin optimizers for fast performance
*/

https://www.php.net/manual/en/ref.dbase.php 4/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

class DBase
{
private $handler = false;
private $searchopt = array (); // Search optimizer

private function unload ()


{
if ($this-> handler !== false)
unset ($this-> handler);
}

public function __construct ($file = false)


{
if ($file !== false)
$this-> load ($file);
}

public function __destruct ()


{
$this-> unload ();
}

public function load ($file)


{
$resource = dbase_open ($file, 0);
$this-> handler = new DBase_Handler ($resource);

return $this-> handler;


}

/* Search
* search for string inside header
* returns record number
* false returned if not found or error occurred
* limit_results gets int or false, limit_results equels one will limit the
* search results for one result only, false for no limit
*/
public function search ($headerText, $string, $limit_results = false,
$handler = false)
{
if ($handler === false)
$handler = $this-> handler;

if ($this-> searchopt [$headerText][$string])


return $this-> searchopt [$headerText][$string];
else
{

https://www.php.net/manual/en/ref.dbase.php 5/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

$size = $handler-> getSize ();


if ( ( $headerNumber = $handler-> getHeaderNumber ($headerText) ) !== false)
{
$results = array ();
for ($i = 1; $i < $size; $i++)
{
$record = $handler-> getRecord ($i, false); // Disabled optimizer to prevent
memory overflow
if (trim ($record [$headerNumber]) == $string)
{
$results[] = $i;

if ( ($limit_results !== false) && (sizeof ($results) == $limit_results) )


break;
}
}

if (sizeof ($results) > 0)


{
$this-> searchopt [$headerText][$string] = $results;
return $this-> search ($headerText, $string, $handler);
}

return false;
} else
return false;
}
}
}

?>

- dbase_handler.php

<?php

/* DBase Handler (dbf)


* handles dbase resource
*/

class DBase_Handler
{
private $resource;
private $size; // Records Count
private $header = array ();
private $dataopt = array (); // Data optimizer

private function setHeader ()

https://www.php.net/manual/en/ref.dbase.php 6/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

{
$this-> header = dbase_get_header_info ($this-> resource);
}

public function __construct ($resource)


{
$this-> resource = $resource;
$this-> setHeader ();
$this-> size = dbase_numrecords ($this-> resource);
}

public function __destruct ()


{
dbase_close ($this-> resource);
}

public function getRecord ($record_number, $dataopt = true)


{
if ($record_number > $this-> size)
return false;
else
{
if ($this-> dataopt [$record_number])
return $this-> dataopt [$record_number];
else
{
$record = dbase_get_record ($this-> resource, $record_number);
if ($dataopt === true) // Data saving optimizer
{
$this-> dataopt [$record_number] = $record;
return $this-> getRecord ($record_number);
} else
return $record;
}
}
}

public function getHeaderNumber ($headerText)


{
foreach ($this-> header as $index => $header)
{
if ($header ['name'] == $headerText)
{
return $index;
break;
}
}

https://www.php.net/manual/en/ref.dbase.php 7/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

return false;
}

public function getHeader ($headerNumber)


{
if ($headerNumber <= sizeof ($this-> header))
return $this-> header [$headerNumber];
else
return false;
}

public function getSize ()


{
return $this-> size;
}
}

?>
up
down
-1
bi.idan [at] gmail.com ¶
15 years ago
some of you contacted me about memo fields and my script, so i'll just post
my answers on the common question here.

(note: this is not an adv for any program, only what i used for myself, and
it's free)

so, there are 2 options if you want to create/read memo fields:

1. use a library for java/c++/c# to build a bridge between php and dbf file.
i've used dbf2java. althougth it's not near complete as my other option, it's
a good start. (http://code.google.com/p/dbf2java-library/)

2. use an external program with pipes to grab the output. i used cdbflite,
(http://www.whitetown.com/cdbflite/). it's free, and pretty much gives you
everything you need to handle those dbf files. i'm not sure about big
databases and it seems you need to register/buy it, but it's again, a start.

hope it helps some of you who needs to handle those database files,

Good luck,
idan
+add a note

dBase

https://www.php.net/manual/en/ref.dbase.php 8/9
12/8/24, 11:46 AM PHP: dBase Functions - Manual

Introduction
Installing/Configuring
Predefined Constants
dBase Functions

Copyright © 2001-2024 The PHP Documentation Group


My PHP.net
Contact
Other PHP.net sites
Privacy policy

Search docs

↑ and ↓ to navigate • Enter to select • Esc to close


Press Enter without selection to search using Google

https://www.php.net/manual/en/ref.dbase.php 9/9

You might also like