php-doc-en/functions/dbase.sgml
James Gingerich 82c6591284 Many minor cleanups.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@9864 c90b9560-bf6c-de11-be94-00142212c4b1
1999-06-20 03:04:56 +00:00

288 lines
9.2 KiB
Text

<reference id="ref.dbase">
<title>dBase functions</title>
<titleabbrev>dBase</titleabbrev>
<partintro>
<simpara>
These functions allow you to access records stored in dBase-format
(dbf) databases.
<simpara>
There is no support for indexes or memo fields. There is no support
for locking, too. Two concurrent webserver processes modifying the
same dBase file will very likely ruin your database.
<simpara>
Unlike SQL databases, dBase "databases" cannot change the database
definition afterwards. Once the file is created, the database
definition is fixed. There are no indexes that speed searching or
otherwise organize your data. dBase files are simple sequential
files of fixed length records. Records are appended to the end of
the file and delete records are kept until you call
<function>dbase_pack()</function>.
<simpara>
We recommend that you do not use dBase files as your production
database. Choose any real SQL server instead; MySQL or Postgres
are common choices with PHP. dBase support is here to allow you
to import and export data to and from your web database, since the
file format is commonly understood with Windows spreadsheets
and organizers. Import and export of data is about all that
dBase support is good for.
</partintro>
<refentry id="function.dbase-create">
<refnamediv>
<refname>dbase_create</refname>
<refpurpose>creates a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>dbase_create</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>array <parameter>fields</parameter></paramdef>
</funcsynopsis>
<para>
The <parameter>fields</parameter> parameter is an array of
arrays, each array describing the format of one field in the
database. Each field consists of a name, a character
indicating the field type, a length, and a precision.
<para>
The types of fields available are:
<variablelist>
<varlistentry>
<term>L</term>
<listitem><simpara>
Boolean. These do not have a length or precision.
</varlistentry>
<varlistentry>
<term>M</term>
<listitem><simpara>
Memo. (Note that these aren't supported by PHP.)
These do not have a length or precision.
</varlistentry>
<varlistentry>
<term>D</term>
<listitem><simpara>
Date (stored as YYYYMMDD). These do not have a length
or precision.
</varlistentry>
<varlistentry>
<term>N</term>
<listitem><simpara>
Number. These have both a length and a precision (the
number of digits after the decimal point).
</varlistentry>
<varlistentry>
<term>C</term>
<listitem><simpara>
String.
</varlistentry>
</variablelist>
<para>
If the database is successfully created, a dbase_identifier
is returned, otherwise false is returned.
<example>
<title>Creating a dBase database file</title>
<programlisting role=php>
// "database" name
$dbname = "/tmp/test.dbf";
// database "definition"
$def =
array(
array("date", "D"),
array("name", "C", 50),
array("age", "N", 3, 0),
array("email", "C", 128),
array("ismember", "L")
);
// creation
if (!dbase_create($dbname, $def))
print "&lt;strong>Error!&lt;/strong>";
</programlisting>
</example>
</refsect1>
</refentry>
<refentry id="function.dbase-open">
<refnamediv>
<refname>dbase_open</refname>
<refpurpose>opens a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>dbase_open</function></funcdef>
<paramdef>string <parameter>filename</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
</funcsynopsis>
<para>
The flags correspond to those for the open() system call.
(Typically 0 means read-only, 1 means write-only, and 2
means read and write.)
<para>
Returns a dbase_identifier for the opened database, or
false if the database couldn't be opened.
</refsect1>
</refentry>
<refentry id="function.dbase-close">
<refnamediv>
<refname>dbase_close</refname>
<refpurpose>close a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbase_close</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcsynopsis>
<para>
Closes the database associated with <parameter>dbase_identifier</parameter>.
</refsect1>
</refentry>
<refentry id="function.dbase-pack">
<refnamediv>
<refname>dbase_pack</refname>
<refpurpose>packs a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbase_pack</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcsynopsis>
<para>
Packs the specified database (permanently deleting all records
marked for deletion using <function>dbase_delete_record</function>.
</refsect1>
</refentry>
<refentry id="function.dbase-add-record">
<refnamediv>
<refname>dbase_add_record</refname>
<refpurpose>add a record to a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbase_add_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>array <parameter>record</parameter></paramdef>
</funcsynopsis>
<para>
Adds the data in the <parameter>record </parameter>to the
database. If the number of items in the supplied record isn't
equal to the number of fields in the database, the operation
will fail and false will be returned.
</refsect1>
</refentry>
<refentry id="function.dbase-delete-record">
<refnamediv>
<refname>dbase_delete_record</refname>
<refpurpose>deletes a record from a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>bool <function>dbase_delete_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>int <parameter>record</parameter></paramdef>
</funcsynopsis>
<para>
Marks <parameter>record</parameter> to be deleted from the database.
To actually remove the record from the database, you must
also call <function>dbase_pack</function>.
</refsect1>
</refentry>
<refentry id="function.dbase-get-record">
<refnamediv>
<refname>dbase_get_record</refname>
<refpurpose>gets a record from a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>array <function>dbase_get_record</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
<paramdef>int <parameter>record</parameter></paramdef>
</funcsynopsis>
<para>
Returns the data from <parameter>record</parameter> in an array. The
array is indexed starting at 1, and includes an associative
member named 'deleted' which is set to 1 if the record has
been marked for deletion (see <function>dbase_delete_record</function>.
<para>
Each field is converted to the appropriate PHP type. (Dates
are left as strings.)
</refsect1>
</refentry>
<refentry id="function.dbase-numfields">
<refnamediv>
<refname>dbase_numfields</refname>
<refpurpose>find out how many fields are in a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>dbase_numfields</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcsynopsis>
<para>
Returns the number of fields (columns) in the specified
database. Field numbers are between 0 and dbase_numfields($db)-1,
while record numbers are between 1 and dbase_numrecords($db).
<example>
<title>Using <function>dbase_numfields</function></title>
<programlisting>
$rec = dbase_get_record($db, $recno);
$nf = dbase_numfields($db);
for ($i=0; $i &lt; $nf; $i++) {
print $rec[$i]."&lt;br>\n";
}
</programlisting></example>
</refsect1>
</refentry>
<refentry id="function.dbase-numrecords">
<refnamediv>
<refname>dbase_numrecords</refname>
<refpurpose>find out how many records are in a dBase database</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<funcsynopsis>
<funcdef>int <function>dbase_numrecords</function></funcdef>
<paramdef>int <parameter>dbase_identifier</parameter></paramdef>
</funcsynopsis>
<para>
Returns the number of records (rows) in the specified
database. Record numbers are between 1 and dbase_numrecords($db),
while field numbers are between 0 and dbase_numfields($db)-1.
</refsect1>
</refentry>
</reference>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->