PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




dbase_get_record

Name

dbase_get_record — Gets the data from a record.

Synopsis

array dbase_get_record(dbf_identifier, record);
int dbf_identifier: dbf identifier
int record: dbf record number

Returns

Array of fields for a given record; FALSE on error

Description

dbase_get_record() fetches the fields from a record and returns them as an array.

An additional element with the key of deleted is added to the end of this array. If the value of this element is set to 1, it indicates that the record will be deleted in the next dbase_pack() function call. The value of deleted is normally set to 0.

If the dbf_identifier argument doesn't refer to an open dbf file, or if the record number is not valid for the referenced dbf file, the function returns FALSE.

Warning

Character fields retrieved from a dbf file may have spaces added to the end of the value. If the value initially inserted into the dbf file was shorter than the defined character field length, the value would have been padded with spaces until it was the length specified in the field definition. (If the value was longer than the field, the value would have been trucated to fit by removing characters from the right side of the string.)

You can remove any spaces at the end of a value with the rtrim() function. Also see trim() and ltrim().()

Note

Numbers returned by this function are converted to the appropriate type in PHP. This behavior means that any numbers entered into the database will have zeros on the left or right side of a value, removed when they're retrieved from the database. In other words, if you insert a value of '01.00' into a dbf file, the value will be converted to 1 upon retrieval.

Version

PHP Version: 3+, 4+

See also

To retrieve field names and values from a dbf file

dbase_get_record_with_names()

Example

Example 226. Read the last record in a dbf file and output a formatted table

<pre>
<?php
# path to dbm file
$db_file = '/tmp/sushi_eaten.dbf';

# Open dbase file for read-only (or die trying)
$id = dbase_open ($db_file, '0')
    or die ("Could not open dbf file <i>$db_file</i>.");

# Find the number of rows in the dbf file
$num_rows = dbase_numrecords ($id)
    or die ("dbf file <i>$db_file</i> is empty.");

# Get the values for the last record in the dbf file
$fields = dbase_get_record ($id, $num_rows);

# Remove the 'deleted' element
unset ($fields['deleted']);

# Turn the array into one long string
$row = '| ' . implode (' | ', $fields) . ' |';

# Find out how long the row is and make a top and bottom for it
$line = str_repeat ('-', strlen ($row));

# Print out a nice little table
print "$line\n$row\n$line\n";

# close the dbf file
dbase_close ($id);
?>
</pre>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.