To create a record, we have two functions i.e ‘createRecord()’ and ‘newAddCommand()’. But we should aware of the difference of these two functions though both are doing same task.
Both the functions need a layout and data array to create a record. So the first difference is the execution process. The ‘createRecord()’ statement requires ‘commit()’ , where as ‘newAddCommand()’ requires ‘execute()’ to complete the request.
|
Ex:
//create record
$rec = $fm->createRecord(‘layout_name’, ‘$data_array’);
$result = $rec->commit();
//new add command
$newAdd = $fm->newAddCommand(‘layout_name’, $data_array);
$result = $newAdd->execute();
Second and main difference is what they return to $result variable. The ‘createRecord()’ statement returns an integer value to know the status of record creation process(whether succeed or failed). But the ‘newAddCommand()’ returns a bunch of information for the new created record along with record id.
|