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



dbase_get_record_with_names — Gets the field names and field data from a record.


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


Associative array of field names and fields for a given record; FALSE on error


dbase_get_record_with_names() fetches the field names and field data from a record and returns them as an associative array. The field names are used as array keys, with the field values being used as the corresponding values.

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.


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().()


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, insert a value of'01.00' into a dbf file and the value will be converted to1 on retrieval.


PHP Version: 3.0.4+, 4+

See also

For retrieving field names and values from a dbf file



Example 227. Print the field names for a dbf file

# path to dbm file
$db_file = '/tmp/sushi_eaten.dbf';

# Open dbase file for read-only
$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 first record in the dbf file
$fields = dbase_get_record_with_names ($id, 1);

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

# Get the key names for the $field array
# ...and convert them into a comma-separated string
$names = implode (', ', array_keys ($fields));

# Print out the field names
print "dbf file <i>$db_file</i> uses the following field names: <i>$names</i>.";

# Close the dbf file
dbase_close ($id);

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 The authors of this book have elected not to choose any options under the OPL. This online book was obtained from 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.