예제 #1
0
 function create($filename, $fields)
 {
     if (!$fields || !is_array($fields)) {
         trigger_error("cannot create xbase with no fields", E_USER_ERROR);
     }
     $recordByteLength = 1;
     $columns = array();
     $columnNames = array();
     $i = 0;
     foreach ($fields as $field) {
         if (!$field || !is_array($field) || sizeof($field) < 2) {
             trigger_error("fields argument error, must be array of arrays", E_USER_ERROR);
         }
         $column = new XBaseColumn($field[0], $field[1], 0, @$field[2], @$field[3], 0, 0, 0, 0, 0, 0, $i, $recordByteLength);
         $recordByteLength += $column->getDataLength();
         $columnNames[$i] = $field[0];
         $columns[$i] = $column;
         $i++;
     }
     $result = new XBaseWritableTable($filename);
     $result->version = 131;
     $result->modifyDate = time();
     $result->recordCount = 0;
     $result->recordByteLength = $recordByteLength;
     $result->inTransaction = 0;
     $result->encrypted = false;
     $result->mdxFlag = chr(0);
     $result->languageCode = chr(0);
     $result->columns = $columns;
     $result->columnNames = $columnNames;
     $result->backlist = "";
     $result->foxpro = false;
     if ($result->openWrite($filename, true)) {
         return $result;
     }
     return false;
 }
예제 #2
0
function xbase_open($filename, $flags = 0)
{
    // - Opens a dBase database - flags : Typically 0 means read-only, 1 means write-only, and 2 means read and write
    if ($flags == 0) {
        $xbase = new XBaseTable($filename);
        if (!$xbase->open()) {
            return false;
        }
    } else {
        $xbase = new XBaseWritableTable($filename);
        if (!$xbase->openWrite()) {
            return false;
        }
    }
    return xbase_addInstance($xbase);
}