Skip to content

FilemakerPro Database Integration

Derek Jones edited this page Jul 5, 2012 · 12 revisions

Discussion Thread at the forums. FilemakerPro is a database product from Apple that works on Windows and Macintosh. It has a SQL interface in the form of ODBC but most people just use the XML export and URL query interface to get data over HTTP. So, it does not fit neatly into the SQL-driven world of database drivers. It would be nice to integrate it with those to take advantage of Active Record and all that, but it's query syntax is quite different and works over HTTP. So, we use FX.php to get it to work nicer with PHP.

FX.php is an opensource PHP library that makes it easy to use FilemakerPro over the web.

I put together what I think is the cleanest integration possible between FX.php and CodeIgniter (CI). It's pretty easy to do.

CI is a PHP Framework that helps you organize code and offers nice integrated libraries. It is also PHP4 and 5 friendly, highly object-oriented, and extendable.

I've been testing out FX.php with CI and I like it a lot.

Here's how I got my set up working:

  1. Download, install and configure CI per the very good instructions at the site. If you have problems, the CI forum is helpful. It should take less than an hour for an intermediate PHP person to get to hello world (welcome_message.php). Time: less than 1 hour.

  2. Once you've got CI running, put the latest copy of FX.php, FX_Error.php, and FX_constants.php in CI's application/libraries/ directory. Time: 5 minutes tops.

  3. Drop this class extension into the same directory with FX.php (CI's application/libraries/ directory).

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/*------------------------------------------------------------------*/
// 20070413 wrapper for CI integration
// needs to be able to init with params in an array
// load these using config file FX.php
/*------------------------------------------------------------------*/
require('FX.php');

class CIFX extends FX {

    function CIFX ($params)
    {
        parent::FX(
        $params['dataServer'],
        $params['dataPort'],
        $params['dataType'],
        $params['dataURLType']
        );
    }

}

?>

This class extension for FX.php lets CI load FX.php with an array as an argument. External libraries like FX.php need no direct modifications to integrate with CI properly - just extend them with a wrapper function that accepts arrays and passes them on.

In summary, you need a new class called CIFX which will be the new constructor. It translates the array passed in by the CI class loader into the 4 parameters the normal FX.php constructor can understand.

Time: Another 5 minutes, tops.

  1. Make a file called CIFX.php (the same name as the class so CI can load it automatically) and put it in CI's application/config/ directory. It should contain the data that is normally found in server_data.php in the FX.php distribution but formatted like a PHP file like this:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| FX FMP database access data
|--------------------------------------------------------------------------
*/

$config['dataServer']='127.0.0.1';
$config['dataPort']='591';
$config['dataType']='FMPro5/6'; // or FMPro7
$config['dataURLType']='http';

?>

CI will load this data and pass it to the new CIFX.php class constructor for you - it can do that because the names are the same. Time: 5 more minutes.

  1. Almost there... make a "controller" file called "search.php" and put it in the application/controllers/ directory with this PHP code (modify the database, layout and field data):
<?php

class Search extends Controller {

function Search()
{
    parent::Controller();    
}

function id($id)
{
    // CI knows where to find the
    // CIFX.php FX wrapper file at
    // CI path: application/libraries/CIFX.php
    // FMP WPE data (IP, port, server version,
    // and url scheme) is in custom config file at
    // CI path: application/config/CIFX.php
    $this->load->library('CIFX');
    // tell FX which DB, layout to use and
    // how many records to return
    $this->cifx->SetDBData('database.fp5', 'layout', 1);
    // build a find request, field name, data, comparison
    $this->cifx->AddDBParam ('id', $id, 'eq');
    // do find, return dataset, no flattening, meta object
    $res = $this->cifx->DoFXAction(FX_ACTION_FIND, TRUE, TRUE);
    echo '<pre>';
    print_r($res);
    echo '</pre>';
}
}
?&gt;

This AddDBParam example assumes you have a database with the fieldname 'id' - you, of course, can change that to suit. I suggest just pointing the FX requests to a database you've already got set up and working. Time: If you use a database already set up, 5 minutes to modify this code and fire it up.

  1. Point your browser to:
http://example.com/path_to_CI/index.php/search/id/1

Note: if you followed the CI install instructions on how to use an .htaccess file to use mod_rewrite for nice urls, then you can drop the index.php and just use:

http://example.com/path_to_CI/search/id/1

CI takes the URL segments and loads one as a controller file (search), calls one as a function (id), and passes the last one as a variable (1) for your id() controller function to use as a search parameter. Nice and sweet. It's a great way of organizing projects!

Let me know if you have problems with this. I'd like to get a little feedback from the FX folks. Post at the CI forums.

Did it take you an hour and 20 minutes? Let me know!

Category:Libraries Category:Libraries::Database

Clone this wiki locally