Run PHP code with FileMaker & bBox

For quite a while, the documentation and product information for bBox has mentioned it as a way to run PHP scripts, but I only just recently realized that we never had any examples of how to do this.

Here are two methods to try.

Both of these examples assume that you will store the scripts in a FileMaker field. Why not just include the PHP script as part of the Set Variable or a Set Field calculation? If you do, you’ll hit a number of headaches dealing with things like nested quotes, escaping control characters, or other issues that make it problematic.

If you don’t already have the bBox plug-in, download it here.

Shell & Here Document

For our first try at this, we’ll use something called a shell here document, which is a convenient method of creating an arbitrary chunk of text in the shell.

Here’s the hybrid shell and PHP script to store in your FileMaker field:

To run the script we execute this function call inside of a Set Variable or Set Field Script step:

And this returns the following result back to FileMaker:

Script by Parameter

If you want to create a subroutine for executing arbitrary PHP scripts, this version may be slightly better.

First we need a field with the PHP code in it:

Then we use the function call below to execute a very short shell script, passing the PHP script in as a parameter:

This should return the same result as our previous example.

For both examples, if running it server-side, you may need to specify the full path to the php command. For the standard Mac OS install it can be found at  /usr/bin/php

Simon

One thought on “Run PHP code with FileMaker & bBox

Leave a Reply