3

Ok so here is the challenge. I have a File maker database on a Filemaker 12 server hosted on a windows box. I also have a PHP form hosted on a Linux box. How do I get the data from the PHP form to the Filemaker database? Here is what I have tried.

<?php
define('fm_host', '131.181.###.###');
define('fm_file', 'name of the db');
define('fm_user', 'user');
define('fm_pass', 'password');
$layout_name = 'Request'; 
$respondent_data = array("stuff","stuff","stuff","stuff","stuff");
require_once ('FileMaker.php');
$fm = new FileMaker(fm_file, fm_host, fm_user, fm_pass);
if(FileMaker::isError($fm)){ 
die('Error - ' . $fm->getCode() . ' ' . $fm->getMessage());
}
$newAdd =& $fm->newAddCommand('Request', $respondent_data);
$result = $newAdd->execute();
?>

This completes with out error yet when I go to Filemaker pro and open up the copy of the database I download form the server using the Filemaker admin console there is no new record. I have unpacked the Filemaker standalone PHP API in the same directory as the form and it manages to use the Filemaker.php functions. So i'm confused as to why their is at least no error thrown. But at this stage of the project I don't care I just want the data in the database by any means! Any hack will do as the scope of the project ends with the data in the database.

Side notes: I have tried ODBC to access DB and considered manual import using file maker pro but PHP installed on the Linux server is missing a com class in the php.ini file and I don't have access to change this.

I have also considered the same thing using XML though i'm not up to speed with it. But like a drunk at 4am, i'm willing to give it a try.

Thanks in advance!

Audo
  • 135
  • 1
  • 2
  • 7
  • 1
    So I tried Print $result; and it returned unable to open file. So I assume that it might have something to do with file permissions on the FMDB server Although i'm not sure at what stage of authentication it fails. Can it find the server at all? Has it found the exact file but just cant open it? – Audo Jan 20 '13 at 22:10
  • Where exactly you get this: "FileMaker.php" ? – mysticalghoul May 31 '18 at 07:31

2 Answers2

3

You need to map fieldnames to the values in the array $respondent_data. Simple key=>value programming style.

$respondent_data = array("field1" => "stuff", "field2" => "stuff", "field3" => "stuff", "field4" => "stuff", "field5" => "stuff");

You can also specify field by field if you want to, like this

$fm = new FileMaker(fm_file, fm_host, fm_user, fm_pass);
$cmd = $fm->newAddCommand($layout_name);
$cmd->setField("fieldname", "Value");
$cmd->setField("fieldname2", "Value2");
$cmd->setField("fieldname3", "Value3");
$result = $cmd->execute();

if(FileMaker::isError($result)){ 
    die('Error - ' . $fm->getCode() . ' ' . $fm->getMessage());
}  

There is no need to call the FileMaker::IsError method before you call $fm->execute(). Thats when PHP uses cURL to query WPE in FileMaker Server. You will get either a FoundSet-Object or Error-Object returned. IsError is a simple way to see if WPE returned an error a set of records.

For more info http://www.filemaker.com/support/product/docs/12/fms/fms12_cwp_php_en.pdf

Kalle
  • 452
  • 2
  • 4
  • 19
1

First, FileMaker themselves recommend that you use a 3rd party database with External SQL Sources when building web apps. This is the only way to get good performance if you're going to have more than a few users hitting it at once.

This would allow you to build your web apps with MySQL, Access, or whatever, and then hook that database to FileMaker so that its tables show up just like other FM tables. Then you can create layouts, scripts, calculations, etc. within FM using the data from the 3rd party database just like it was actual FM data.

If you want to stick with the PHP API you need to make sure the file is actually running on the server and you simply open it using Pro. I'm a little confused how you said you were downloading it to run in Pro..?? You don't download it...you just open it from the remote server.

Then you need to make sure the file has the PHP API enabled for the user you're connecting with via the Security settings in FM. I recommend creating a user specific to your web apps and give it nothing but PHP API access.

Then when you connect form your web apps with that user you should be good to go.

Drew Angell
  • 25,968
  • 5
  • 32
  • 51
  • 1
    I believe this is truly the best way to go. It turns out the DBA although he said the permissions were enabled, they were not. Thanks for your incite. – Audo Jan 23 '13 at 23:52