[FX.php List] Memories....MORE

Jonathan Schwartz jschwartz at exit445.com
Thu May 13 08:24:40 MDT 2010


Thanks very much, Anders.  I will need some time to digest this. 
After 5 years or so of learning fx.php/FMI API/PHP, I feel like  a 
freshman all  over again as I turn the page to learn functions, and 
then perhaps OOP.  I need a hug.  ;-)

J



At 9:11 AM -0500 5/13/10, Anders Monsen wrote:
>Here's another possible option. There are many ways to skin this cat.
>
>function createNew( $dbname, $layoutName , $fieldsArray) {
>	$fm = new FileMaker( $dbname, FM_HOST);
>	$fm->SetProperty( 'username', FM_USER );
>	$fm->SetProperty( 'password', FM_PASS );
>	$add =& $fm->newAddCommand( $layoutName );
>   	foreach($fieldsArray as $k=>$v) {
>		$add->setField($k,$v);
>	}
>	$result = $add->execute();
>
>	if( FileMaker::isError( $result ) ) {
>		$error_code = $result->code;
>		return $errorCode;
>	} else {
>		return $result;
>	}
>
>}
>
>Store this in a function.php page with some additional lines, ie.
>require_once('FileMaker.php');
>define('FM_HOST', 'IP');
>define('FM_USER', 'account_name');
>define('FM_PASS', 'password');
>
>Your array of values contains the fieldname and the value, ie.
>$newValues = array();
>$newValues['FIELD_NAME'] = $_POST['SUBMITTED_VALUE'];
>etc.
>etc.
>
>In the page that calls the function, include the functions.php page, 
>and send the query using something like:
>	$createFM = createNew( 'DB_NAME', 'LAYOUT_NAME' , $newValues );
>
>	IF statement to check for errors....	or create separate 
>error checking function
>
>	ELSE
>	$records	= $createFM->getRecords();
>	$record	= $records[0];
>	$recid	= $record->getRecordID();
>
>If you have multiple databases or layouts where you need to create 
>records, it may be easier to submit these via the function than 
>store them inside the function.
>
>--
>Anders Monsen
>
>On May12, 2010, at 2:48 PM, Jonathan Schwartz wrote:
>
>>  OK. How about a gentle push in the right direction? It's a big 
>>jump from example code to doing creating a function for an entire 
>>query, using a dozen or so variables.
>>
>>  Here is my log.php query "add" code using the API.  Do I need to 
>>define every variable in the function definition? What about the 
>>first two lines that contain includes?
>>
>>
>>  Existing Log Code:
>>			require_once('Connections/log_prefs.php');
>>			require_once('FileMaker.php');
>>			$log_add = $log->newAddCommand('web');
>>			$log_add_fields = array(
>>			'DB'=>'ABCD',
>>			'IP'=> $IP,
>>			'Browser'=> $AGENT,
>>			'hostname'=> $_SESSION['hostname'],
>>			'sessionid'=> $sessionid,
>>			'Location'=> $_SERVER['PHP_SELF'],
>>			'Step'=>$Step,
>>			'Detail'=> $Detail,
>>			'Name'=> $Name,
>>			'ZipCode'=>$Zip,
>>			'Route'=>$Route,
>>			'Message'=>$Message,
>>			'mode'=>$_SESSION['loginmode'],
>>			'type'=>$_SESSION['type'],
>>			'elapsed'=>$timeelapsed,
>>			'CustID'=>$_SESSION['Customer_ID_Number'],
>>			'Rep'=>$_SESSION['LastName'],
>>			'users'=>$_SESSION['OnlineUsers'],
>>			'Region'=>$_SESSION['Region'],
>>			'referer'=>$referer,
>>			'CustTempRecID'=>$TempRecID
>>			);
>>
>>			foreach($log_add_fields as $key=>$value)
>>			{
>>			$log_add->setField($key,$value);
>>			}
>>			$log_add_results= $log_add->execute();
>>
>>			if(FileMaker::isError($log_add_results))
>>			{
>>				$error_code = $log_add_results->code;
>>				exit;
>>			}else{
>>				$log_row = 
>>current($log_add_results->getRecords());
>>			}
>>
>>
>>  Thanks for the help.
>>
>>  Jonathan
>>
>>
>>  --
>>  Jonathan Schwartz
>>  Exit 445 Group
>>  jonathan at exit445.com
>>  http://www.exit445.com
>>  415-370-5011
>>  _______________________________________________
>>  FX.php_List mailing list
>>  FX.php_List at mail.iviking.org
>>  http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>>
>
>_______________________________________________
>FX.php_List mailing list
>FX.php_List at mail.iviking.org
>http://www.iviking.org/mailman/listinfo/fx.php_list


-- 
Jonathan Schwartz
Exit 445 Group
jonathan at exit445.com
http://www.exit445.com
415-370-5011


More information about the FX.php_List mailing list