Site icon David Yin's Blog

How to connect DBF file and read data by PHP script

Afte last post, my php-fpm support the dbase database file now.  Here is an example php script.

$db = dbase_open('../db/clients.dbf',0);

if ($db){
	$record_numbers = dbase_numrecords($db);
	
	for ($i = 1; $i <= $record_numbers; $i++) {
		  $row = dbase_get_record_with_names($db, $i);
		  if ( strpos(trim($row['CLIENTNAME']), $clientname)  !== FALSE and $row['deleted'] != 1) {
			  	$clientid =  $row['CLIENTID']);
				
				echo 'Customer ID Number: ',$clientid,';
                 }
     }
}

0) The dbase file has two columns, one is CLIENTID, the other one is CLIENTNAME.

1) Open the dbase file, clients.dbf,  by relative path.

2) If the dbf file exists, get the total number of records.

3) Go through all records. If field CLIENTNAME is same as the variable, $clientname,  print client id.

Exit mobile version