With our 2.9 plugin function we added PHP functions. Those functions allow you to load the PHP library from file system and use it. This gives you tons of new functionality with our plugin for either reusing PHP code from your website or by solving new issues with PHP.
We include a copy of the php library for your convenience with the plugin download. In your startup script you can find the library and load it to have PHP ready when you need it. If you like, you can compile your own PHP library with a custom set of extensions. For that you find instructions in the ReadMe file included with PHP examples.
So once your solution located the php library and got the native path, please call the PHP.Load function. Next you call PHP.Init function to initialize the PHP engine. If needed you could also use PHP.ShutDown to shutdown, but most times you let it run until Filemaker quits.
First we have PHP.Execute, a convenient function to pass some PHP code and get the result of the function. With result we mean the plugin captures all output to standard output in PHP. Normally you write something there with print or echo commands. So here you either get "[MBS] Failed. Bad Syntax?" or the output. As you see the PHP interpreter can fail to parse your script due to an syntax error. But if everything is correct, the script should run just fine.
We do recommend to use php exception handling and report errors in a way where your Filemaker solution can handle the error gracefully.
Instead of Execute you can also run PHP.Run and PHP.GetResultString. This way you can check if PHP.Run returns "OK" and pick result later.
PHP has global variables and we have a couple of plugin functions related to it. With PHP.ExistsVariable you can check if a variable with a given name exists. With PHP.SetVariable you can set a variable with a text value. And PHP.GetVariable gives you a variable value as text. If the variable is not text, it will be converted. You can of course use JSON or Base64 functions here for handling binary or object data.
Our plugin expects text from PHP to be ISO 8859-1 encoded and also all text passed in for source code or variables. Maybe we someday change that to UTF-8. To be save you can of course use base64 encoding for your data, especially for passing raw byte strings.
Our plugin defines a new PHP module called FilemakerModule. This module has 3 functions: FMScript, FMEvaluate and FMExecuteSQL.
You can call FMScript in your PHP script and pass up to three parameters. This function works like FM.RunScript. First is the name of a database file, second the name of the script and third the optional text parameter. The plugin will call the script soon. Soon as Filemaker script calls from plugin are queued and executed later.
echo FMScript("Simple_php", "TestScript", "Hello World");
The FMEvaluate function takes a text parameter with a string to evaluate. This way you can query things from Filemaker like variables or call functions. Useful for functions like Get(UserName).
The FMExecuteSQL function now runs SQL code just like FM.ExecuteSQL. First parameter is the SQL command. Second parameter defines the ASCII code of the column delimiter and third parameter the row delimiter. Default for column delimiter is tab (9) and for rows it is return (13). The result is passed back to PHP.
echo FMExecuteSQL("select * from Contacts");
To get the list of extensions, you can run this PHP code:
print_r(get_loaded_extensions());This shows currently on Mac OS X:
ArrayAs you see we have all the famous names like sqlite (database), zlib and zip (zip compression), pcre (Regular expressions), ftp, curl and even soap.
 => Core
 => date
 => ereg
 => libxml
 => pcre
 => sqlite3
 => zlib
 => bcmath
 => bz2
 => calendar
 => ctype
 => curl
 => dom
 => hash
 => fileinfo
 => filter
 => ftp
 => SPL
 => iconv
 => json
 => session
 => PDO
 => pdo_sqlite
 => standard
 => posix
 => Reflection
 => Phar
 => SimpleXML
 => soap
 => sockets
 => exif
 => tokenizer
 => xml
 => xmlreader
 => xmlwriter
 => zip
 => FilemakerModule
If you have questions, please do not hesitate to ask us.
This article is for Filemaker, but we have the same functionality available also in the MBS Real Studio PHP Plugin.