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);
require_once (SITE_PATH. '/server/php/libs/dbase/handler.php');
class DBase
{
private $handler = false;
private $searchopt = array (); 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;
}
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
{
$size = $handler-> getSize ();
if ( ( $headerNumber = $handler-> getHeaderNumber ($headerText) ) !== false)
{
$results = array ();
for ($i = 1; $i < $size; $i++)
{
$record = $handler-> getRecord ($i, false); 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
class DBase_Handler
{
private $resource;
private $size; private $header = array ();
private $dataopt = array (); private function setHeader ()
{
$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) {
$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;
}
}
return false;
}
public function getHeader ($headerNumber)
{
if ($headerNumber <= sizeof ($this-> header))
return $this-> header [$headerNumber];
else
return false;
}
public function getSize ()
{
return $this-> size;
}
}
?>