mfcdb_create

Create a new table


Prototype:

resource mfcdb_create( string $dbfile, int $rec_len, resource $primary_key [, int $db_flags ])




This function create a new table with couple of files .idx and .dat with name $dbfile. The table is setup with lenght of record specified by $rec_len and with primary key $primary_key. An optional argument $db_flags permit you to specify flags relating lock modes etc…

Database Flags

MFC_VARLEN Sets table with variable record length
MFC_FIXLEN Sets table with fixed record length



RETURN: This function returns a resource to the handle of table or FALSE if some error occurred. In this case you can get string error code using mfcdb_error()

Example

<?php
 
$keyResource = mfcdb_key(MFC_ISNODUPS, 1, 0, 18, MFC_CHARTYPE);
 
if($keyResource == FALSE) {
  die("Error creating key.");
}
 
$resource = mfcdb_create("mydatabase", 47, $keyResource);
 
if($resource == FALSE) {
  die("An error occurred creating table, error is: ".mfcdb_error()."\n");
}
 
$record = "0101001Test record length n bytes");
$record = sprintf("%47s", $record);
 
$result = mfcdb_insert($resource, $record);
 
if($result == FALSE) {
  echo "An error occurred while inserting record, error is: ".mfcdb_error()."\n";
} else {
  echo "Inserted record ".$result."\n";
}
 
if(mfcdb_close($resource) == FALSE) {
  die("An error occurred closing table, error is: ".mfcdb_error()."\n");
}
 
?>
mfcdb_create.txt · Ultima modifica: 2008/08/22 23:07 da gchiesa