mfcdb_key

Create a key resource in order to build new table or add new key to existing table.


Prototype:

resource mfcdb_key( int $key_flags, int $key_nparts, int $kp_start, int $kp_len, int $kp_type [, …] )




This function create a key resource, useful when you build a new table or add more keys to existing table. The $key_flags are specified in section below, the $key_nparts specify how many parts is composed the key. The function accept variable argument list rappresented by $kp_start, $kp_len, $kp_type variables for each $key_nparts declared.

Key Flags

MFC_ISNODUPS Key without duplicates (es. PRIMARY KEYs)
MFC_ISDUPS Key with duplicates
MFC_DCOMPRESS Key with compression
MFC_LCOMPRESS Key with compression
MFC_TCOMPRESS Key with compression


For each key part you can specify the key type as following scheme:

Key Part Types

MFC_CHARTYPE
MFC_INTTYPE
MFC_LONGTYPE
MFC_FLOATTYPE
MFC_QUADTYPE



RETURN: The function returns a resource that can be used to create new table or add more keys. If an error occurred it returns FALSE.

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");
}
 
?>
documentation/mfcdb_key.txt · Ultima modifica: 2008/08/22 23:00 da gchiesa