3

How can I write a script which calls my PHP code? This script should contain records which are in Filemaker Database.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
Prasad007
  • 103
  • 3
  • 7

4 Answers4

1

You can use the "Insert from URL" script step to call PHP and make it do something. I was able to use this in a server-side script to call a PHP script with some params in the URL. This allowed me to have Filemaker talk to a PHP API of another service. Not sure if that answers your question (or if it is even still a question), but thought that I'd share.

Brian
  • 11
  • 1
1

I had a similar problem, where I wanted a FileMaker action to trigger a script that would alert a website that something had changed. I was working in FileMaker Pro 11 so Insert from URL wasn't an option (though how I wish it had been)!

I created a FileMaker script called Sync and gave it one action: Perform AppleScript (obviously this works on Macs only; you can achieve something similar using Send DDE Execute in Windows).

In the Script Step Options, I set my Perform Applescript to be a Calculated AppleScript, and set it as follows:

"do shell script \"curl http://example.com/sync.php?id=" & Get( RecordID ) &
"\\\&layout=" & GetAsURLEncoded( Get( LayoutName ) ) & "\\\&table=" & 
GetAsURLEncoded( Get( LayoutTableName ) ) & "\""

Note all the quotes and escaping of quotes.

To cause this to execute when something changes, go to File » Manage » Layouts and select the layout where a user might be editing a record, then click Edit. In the resulting Layout Setup dialog, go to Script Triggers and for the event OnRecordCommit, select the Sync script you just created.

Now whenever a record is modified in that layout, the Sync script will run which executes the AppleScript which executes the shell command curl, sending a GET request something to the effect of:

curl http://example.com/sync.php?id=123&layout=Edit%20Records&table=Records

From there, create a sync.php to do something intelligent whenever it’s loaded, using $_GET['id'] and $_GET['layout'] and $_GET['table'] or similar passed-through variables.

One caveat with this approach is that FileMaker is frozen while the shell script executes, which in this case means until curl either receives a response or times out. While you can set the timeout to be very low (add arguments --output /dev/null --silent --head --fail --connect-timeout 1), it still causes a delay to the user of a second or so, which can be noticeable if a user is editing lots of records. If anyone has a solution for this, or a way to cause the script to run asynchronously in the background, please let me know.

Geoffrey Booth
  • 7,168
  • 5
  • 35
  • 42
0

Yes, there is a PHP API available for FileMaker:

http://www.filemaker.com/downloads/pdf/article2_php.pdf

Jesse Barnum
  • 6,507
  • 6
  • 40
  • 69
  • Can you tell me any Filemaker script if I'm retrieving records from 'Users' table and fields are 'username' and 'password' which are in Filemaker database. I wants to display all the records using php. – Prasad007 Jun 14 '11 at 14:28
  • You won't want to call a FileMaker script for that purpose. A FileMaker script is similar to a stored procedure; you wouldn't call a stored procedure to simply select the contents of fields from a table. There are functions in the API to select fields from a table; just check the documentation. – Jesse Barnum Jun 14 '11 at 16:47
  • Thanx Jesse Now I'm using Filemaker API to retrieve the records but problem is,it is not retrieving records from Filemaker database.Can you tell me why this is happening.. – Prasad007 Jun 14 '11 at 17:31
  • No, I have no way of know why it's not working for you. You'll need to troubleshoot this based on the documentation and whatever error message you're getting. – Jesse Barnum Jun 15 '11 at 14:15
  • I'm using Filemaker API in PHP to retrieve the records from Filemaker Pro 11 Advance Database. But its showing error. Error: Communication Error: (22) The requested URL returned error: 404 - This can be due to an invalid username or password, or if the FMPHP privilege is not enabled for that user. Though I have set all Extend Privileges and gave it to user. – Prasad007 Jun 16 '11 at 09:16
-1

Before you work on adding coding for your own file, try getting the sample API code to work with the FMServer_Sample database.

andyknas
  • 1,939
  • 2
  • 15
  • 29