Performing a Compound Find Using FileMaker API for PHP

January 8, 2010 by phin

If you are interested in designing your own website utilizing FileMaker, you will undoubtedly have to familiarize yourself with the FileMaker API for PHP documentation. Developing a basic php page to perform a compound find in FileMaker, will be a good introductory.

1. In order to utilize the FileMaker API for PHP, your php page must include it. This is done with the require_once statement.

  • require_once (‘FileMaker.php’);

2. Connect to your FileMaker solution using database class and the setProperty statements. You should not that the setProperty statements are case sensitive.

  • $fm = & new FileMaker();
  • $fm->setProperty(’database’, ‘YourDatabaseName’);
  • $fm->setProperty(’username’, ‘test’);
  • $fm->setProperty(’password’, ‘mypassword’);

3. The php page now has all the information it needs to interact with your FileMaker solution. Now we can tell it to do a compound find using the newFindCommand and addFindCriterion statements in FileMaker API. These two statements are also case sensitive.

4. After adding the search criteria you will than need to execute the find. The result of the find should be stored in a variable. The variable, if no error occurs, will be an array of FileMaker records.

  • $result = $findCommand->execute();

5. Utilizing basic php codes, we can check for errors and display our FileMaker records on the web. Using the getField statement will be required from the FileMaker API.

  • if (FileMaker::isError($result)) { echo “<p>Error has occurred: ” . $result->getMessage() . “</p>”;exit;}

A very important thing to know is that FileMaker API for PHP is layout based oriented. In order for your command statements to work, it must point to the correct layout and field within your FileMaker solution. Meaning that the layout you are referring to on your php page must always exist and it must contain the field(s) you are referring to as well.
You can refer to a complete copy of the sample coding below:

example

For a reference to FileMaker API for PHP click here.


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment