FILEMAKER API FOR PHP 12 - A PRACTICAL GUIDE FOR CREATING DATABASE DRIVEN WEB SITES WITH FILEMAKER PRO 12 AND FILEMAKER SERVER 12 - TODD DUELL, M.B.A.

Page created by Roger Powell
 
CONTINUE READING
FILEMAKER API FOR PHP 12 - A PRACTICAL GUIDE FOR CREATING DATABASE DRIVEN WEB SITES WITH FILEMAKER PRO 12 AND FILEMAKER SERVER 12 - TODD DUELL, M.B.A.
FileMaker API for PHP 12
       A Practical Guide for Creating Database Driven Web Sites with
                 FileMaker Pro 12 and FileMaker Server 12

 Todd Duell, M.B.A.
FILEMAKER API FOR PHP 12 - A PRACTICAL GUIDE FOR CREATING DATABASE DRIVEN WEB SITES WITH FILEMAKER PRO 12 AND FILEMAKER SERVER 12 - TODD DUELL, M.B.A.
© 2012, Todd Duell. All Rights Reserved. No part of this book shall be reproduced, stored in a retrieval system, or
transmitted in any means, electronic, mechanical, photocopying, recording, or otherwise, without the expressed
written permission from the author. No patent or copyright liability is assumed with respect to the use of the
information contained herein. Although every precaution has been taken in the preparation of this book, the
author assumes no responsibility for errors or omissions. Nor is any liability assumed for damages resulting from
the use of the information contained herein.

All terms mentioned in this book that are known to be trademarks or service marks have been appropriately
noted. The author cannot attest to the accuracy of this information. Use of a term in this book should not be
regarded as affecting the validity of any trademark or service mark. FileMaker and the FileMaker logos are the
trademarks of FileMaker Inc. PHP and the PHP logo are the trademarks of PHP. More information regarding
these trademarks may be found on their respective web site at www.filemaker.com and www.php.net.

Disclaimer: Every effort has been made to make this book as complete as possible, however no warranty or
fitness is implied. The information is provided on an “as is” basis. There is no one correct method to achieve the
recommended results. Therefore, you may discover additional resources that are either similar or more efficient
than what is described in this book. The author shall have neither liability nor responsibility to any person or entity
with respect to any loss or damages arising from the information contained in this book or any databases or
sample materials accompanying it. The author may be contacted at tduell@formulationspro.com.

ISBN-13: 978-0-615-71807-1
ISBN-10: 0-615-71807-1
Table of Contents
Introduction............................................................................................................................... 1

About the Author ...................................................................................................................... 4

Part I — Getting Ready for Web Publishing
          Create a Table ..................................................................................................................................................... 5

          Create a Form...................................................................................................................................................... 6

          Create a Link ....................................................................................................................................................... 7

          Meta Refresh ....................................................................................................................................................... 8

          Designing a Web Application.............................................................................................................................. 8

Part II — Web Server Installation
          Apache on OS X................................................................................................................................................ 11

          IIS Server 6 on Windows XP ............................................................................................................................ 12

          IIS Server 7.5 on Windows 7 ............................................................................................................................ 14

          Localhost vs. your Production Server .............................................................................................................. 17

Part III — FileMaker Server Installation
          Single Server Model .......................................................................................................................................... 19

          Installing PHP .................................................................................................................................................... 23

          Configure Clients ............................................................................................................................................... 26

          Configure Databases ........................................................................................................................................ 26

          Configure Web Publishing ................................................................................................................................ 32

          Testing your PHP Installation ........................................................................................................................... 35

          Uploading the “php_demo.fmp12” Database File ........................................................................................... 37

PART IV — Choosing a RAD Tool vs. a Free Text Editor
          Dreamweaver .................................................................................................................................................... 41

          BBEdit ................................................................................................................................................................ 41

          TextWrangler ..................................................................................................................................................... 42

          Nvu ..................................................................................................................................................................... 42

          Zend Studio........................................................................................................................................................ 42

PART V — Introduction to PHP
          w3schools.com .................................................................................................................................................. 43
php.net ............................................................................................................................................................... 44

     FileMaker Server 12 Custom Web Publishing with PHP................................................................................ 45

     FileMaker API for PHP Tutorial ........................................................................................................................ 46

     FileMaker API for PHP Examples .................................................................................................................... 48

     PHP Reference Guide....................................................................................................................................... 49

     Formulations Pro PHP Site............................................................................................................................... 50

     How PHP is Like FileMaker .............................................................................................................................. 51

     RecordID vs. Serial Number ............................................................................................................................. 52

     Layouts, Not Table Access ............................................................................................................................... 53

     Naming Conventions ......................................................................................................................................... 54

     Syntax ................................................................................................................................................................ 55

     Includes .............................................................................................................................................................. 55

     Comments.......................................................................................................................................................... 55

     Quotes ................................................................................................................................................................ 56

     Variables ............................................................................................................................................................ 56

     Concatenation.................................................................................................................................................... 57

     Operators ........................................................................................................................................................... 58

     If/Else ................................................................................................................................................................. 58

     Looping............................................................................................................................................................... 59

     Arrays ................................................................................................................................................................. 60

     Forms — $_GET, $_POST. $_REQUEST ...................................................................................................... 60

Part VI — Sample Database
     Table Structure .................................................................................................................................................. 62

     Fields .................................................................................................................................................................. 63

     Field Validation .................................................................................................................................................. 65

     Value Lists ......................................................................................................................................................... 66

     Scripts ................................................................................................................................................................ 67

     Layouts............................................................................................................................................................... 68

     Portals ................................................................................................................................................................ 68

     Web Viewer........................................................................................................................................................ 69

     Accounts and Privileges.................................................................................................................................... 69
Security .............................................................................................................................................................. 70

      Enabling PHP Access ....................................................................................................................................... 71

Part VII — Publishing FileMaker Data with PHP
      dbaccess Include File........................................................................................................................................ 74

      Container Bridge File ........................................................................................................................................ 76

      PHP Info ............................................................................................................................................................. 78

      Find All Records ................................................................................................................................................ 79

      Sort Records, User Defined.............................................................................................................................. 82

      Sort Records, Fixed........................................................................................................................................... 85

      Search Records, Simple ................................................................................................................................... 87

      Search Records, Compound ............................................................................................................................ 90

      Search->Detail................................................................................................................................................... 93

      Insert Record ..................................................................................................................................................... 97

      Insert Record with Validation .......................................................................................................................... 100

      Delete->Detail .................................................................................................................................................. 105

      Edit->Detail ...................................................................................................................................................... 110

      Search Portal->Detail Portal ........................................................................................................................... 115

      Insert Portal Record ........................................................................................................................................ 119

      Edit Portal Record ........................................................................................................................................... 124

      Delete Portal Record ....................................................................................................................................... 131

      Display Container Field................................................................................................................................... 138

      Display URL Image ......................................................................................................................................... 140

      Upload File ....................................................................................................................................................... 142

      Display Externally Stored Container Field ..................................................................................................... 149

      Display a List Menu ......................................................................................................................................... 151

      Display a List Menu Using Two Fields ........................................................................................................... 154

      Display Search Results ................................................................................................................................... 157

      Create a Log In Procedure ............................................................................................................................. 160

      Log Out Inactive Users ................................................................................................................................... 166

      Alternate Background...................................................................................................................................... 171
Run a Script — Update Records .................................................................................................................... 174

Run a Script — Delete Records ..................................................................................................................... 179

Run a Script — Send Mail .............................................................................................................................. 183

Display Record Pagination ............................................................................................................................. 186

Display Record Navigation ............................................................................................................................. 191

Multi User Process to Edit Records ............................................................................................................... 196

Run a Script — Import XLS File ..................................................................................................................... 201

Boolean Check Box......................................................................................................................................... 209

Multi Value Check Box .................................................................................................................................... 213

Multi Value List ................................................................................................................................................ 217

Pre Validate Data Before Update................................................................................................................... 221

Perform Compound Search ............................................................................................................................ 227

Quick Find Across All Fields ........................................................................................................................... 231

Google reCAPTCHA ....................................................................................................................................... 236

Display a Random Banner Ad ........................................................................................................................ 239

Duplicate Record ............................................................................................................................................. 241

Duplicate Related Records ............................................................................................................................. 245

Install and Configure SSL to Work with FileMaker Server ........................................................................... 251

PHP with AJAX ................................................................................................................................................ 262

PHP Calendar .................................................................................................................................................. 267

Compare Dates ............................................................................................................................................... 276

Display HTML/CSS using PHP ...................................................................................................................... 280

Expire Download Links ................................................................................................................................... 283

Google Pie Charts ........................................................................................................................................... 289

Google Bar Charts........................................................................................................................................... 293

Google Line Charts ......................................................................................................................................... 297

Google Map API Store Locator ...................................................................................................................... 302

Google Map API Geocodes ............................................................................................................................ 307

Google Map API Map Markers ....................................................................................................................... 310

Jump Menu ...................................................................................................................................................... 316

Multiple Email Attachments ............................................................................................................................ 319
Submit Miltiple Page Forms............................................................................................................................ 327

      Print PDF Report ............................................................................................................................................. 332

      Select and Update Multiple Records.............................................................................................................. 336

      Subsummary Report ....................................................................................................................................... 340

      Validate Credit Cards ...................................................................................................................................... 344

      Validate Phone Number .................................................................................................................................. 351

Part VIII — Additional Information
      Extended FileMaker vs. PHP Syntax ............................................................................................................. 354

      Other Methods — PHP/ODBC, ASP, JSP, IWP ........................................................................................... 357

      Costs ................................................................................................................................................................ 360

      Performance Considerations .......................................................................................................................... 363

      Security ............................................................................................................................................................ 366

      Error and Server Logs..................................................................................................................................... 368

      FileMaker Error Codes .................................................................................................................................... 370

      FileMaker API for PHP Reference ................................................................................................................. 376

      Index................................................................................................................................................................. 379
Introduction
Welcome, and thank you for acquiring FileMaker API for PHP 12, A Practical Guide for Creating Database Driven
Web Sites with FileMaker Pro 12 and FileMaker Server 12. If you’re reading this book I’m acutely aware that you
have been challenged to publish data from your FileMaker Pro database to the web. Many of you have no web
publishing experience, have experience on other platforms and technologies, and/or are frustrated by the lack of
documentation, examples, third party products, and available rapid application development tools to publishing
data from a FileMaker database. The FileMaker API for PHP has only been available since 2007. Therefore, I will
assume that you are at least new to the FileMaker API for PHP and are seeking out resources to assist you to
publish your data to the Internet in an efficient and professional manner.

This book starts by demonstrating basic HTML that you should already be familiar with. If you are not already
familiar with HTML you should seek out a book or other on-line resource to help you understand how to work with
basic tables, forms, links, etc. When publishing data from a database you will be required to know how to create
the tags such as headers, table rows, and table data to display your data correctly. If you can master this, you can
create a dynamic web page to display your data. I don’t want to scare you right up front. It’s actually quite easy.
However, like anything else, it does take practice and vision to know how you want the page to be displayed.

Section II of the book deals with enabling either Apache on OS X or IIS Server on Windows. Both platforms
support PHP. The nice part is that the FileMaker Server installation process will install PHP and turn everything
on (for the most part). Your choice is simply to decide which platform you want to use to host your web site. The
most important consideration for a server is to develop on the same platform on which your web site will be
hosted, weather that be an in-house server or a third party hosted server. Although it’s not required, it does make
testing and deployment that much easier.

Part III discusses your FileMaker Server installation. If you were wondering, you only need FileMaker Server to
host your solution, not FileMaker Server Advanced. That saves you quite a bit of money. Unfortunately, you can’t
use FileMaker Pro or FileMaker Advanced as a development tool when accessing the data via PHP. So you will
have to break down and purchase FileMaker Server.

In Part IV, this book covers the use of rapid application development (RAD) tools versus “free” text editors. You
have to develop your web pages in some type of text editor. The question is how much money are you willing to
spend to improve your productivity and extensibility. There are definite advantages to utilizing professional tools.

Part V is where we start to dig in. It’s imperative that you learn some basic PHP. I’m not going to pretend to be an
expert PHP developer as there is just too much to learn on top of everything else. However, a little bit of
knowledge goes a long way. As in any programming language, you use maybe 80% of the available methods on
a routine basis and you look up the other 20% only when you need to use them. This book is going to make you
hand code PHP. Yes, I can hear you grumbling. The problem is that there are no complete RAD tools to do
everything that you need for professional solutions. So it’s best to learn it the hard way the first time, then use the
tools that are available to supplement your work.

Part VI is an overview of the provided sample database. It does not go into excruciating detail about how to create
a FileMaker Pro database. I’m going to assume that you already know how to do that. The database is very
simple. It is used to demonstrate specific techniques for acquiring data from layouts, fields, value lists, portals,
and how to run scripts. It does cover every possible scenario that you would build in a commercial application. I
believe that it’s better to focus on the PHP methods rather than throwing a curve ball at you with unnecessary,
complicated database structure or an esoteric topic. If you have a simple database to start with you can apply the
same PHP code to far more complicated systems.

If you are already comfortable with building a FileMaker Pro database and PHP you can skip right to Part VII. The
lessons are broken down unto two basic sections. The Core section is what I consider to be the basic techniques
and code that you will need to understand to build any successful web application. The Advanced section is just
that — advanced topics and third-party API integration. Once you understand the Core topics you can pick and
choose the Advanced topics that fit your needs. The Core lessons start off slow specifically for beginners. They
demonstrate all the basic techniques to search, display, add, edit, and delete records. Then they graduate into
more complex PHP and FileMaker methods to do things such as display container images, sessions, login
routines, email, running scripts, etc. The main focus of this book is to provide complete, professional, production
quality examples. You should be able to take these techniques and use them immediately in your own work. I will
point out that there are many ways to accomplish the same end result. As such the lessons will create the content

                                                          1
using a variety of methods so you can pick and chose the one that fits your programming style the best. The more
techniques you learn, the better the programmer you will become.

The book wraps up section VIII with reference material to other web publishing technologies that you can use with
FileMaker Server and Server Advanced. Next is the cost, which is always an important consideration. Then topics
to consider for performance and security expectations. Where to find more information about logs and the
FileMaker API for PHP reference guide as a last resort when things go wrong. Finally, the new FileMaker PHP
web site at www.formulationspro.com designed to be the leading developer community for all the PHP methods.
User’s can freely access this repository of information and best practices code as well as share content and
examples with other developers around the world.

I have a few closing comments regarding the upgrade to the FileMaker 12 product line. Gone from FileMaker
Server is the PHP Site Assistant. That means you really have to learn how to program the API from scratch.
There are no RAD tools to help you. If you’re desperate and you have an old copy of FileMaker Server 11 you can
still refer back to the Site Assistant there. However, FileMaker Server 11 and FileMaker Server 12 cannot co-exist
on the same computer and the new database is a file format change (fp7 vs. fmp12), which means you’d have to
be developing two versions in parallel or reverse-engineering specific components for testing. I was never a fan of
the generic Site Assistant anyway. You’re better off without it. In most cases your migration to FileMaker Server
12 will involve buying a new server to migrate databases as they are converted. Keep in mind, just because
FileMaker can automatically convert files, doesn’t mean that things don’t break. Plugins are a problem and so are
graphics. The new user interface and graphic tools can severely affect your previous layout design if you used
things such as drop shadows on fields. You still have to test converted files! FileMaker also worked quite a bit on
performance and stability with the web publishing engine and the web publishing core. You should see some
minor performance gains with the upgrade. Outside of that the API is pretty much the same. The only notable
exception is the new getContainerDataURL method to retrieve images and files stored externally from the
database. That new feature will be covered in this book. Lastly, I have spent an exhaustive amount of time re-
testing every line of code. As it turns out, there are a whole slew of new bugs in the various web browsers, web
publishing engine, IIS Server, and PHP. All of these bugs have been noted and accommodated in this completely
revised book. Therefore, even if you have the previous version of the book it may be well worth your time to study
the new content in this book.

There are several conventions used in this book:

Localhost

Local host refers to your development server. The URLwill typically be http://l127.0.0.1

        DO NOT use http://localhost on a Windows server. Windows has problems trying to resolve localhost to
        127.0.0.1, which can create major performance problems and even crashing issues.

Production Server

Production Server refers to your web server that is hosting the solution to the Internet. The URL will typically be
http://www.mycompany.com

Code Samples

PHP code will be displayed in Courier font to make separating the code from the discussion easier.

                                                          2
Special Content

Special content or discussion will be called out to your attention.

           Notes specific to the use of the FileMaker database will display the FileMaker Advanced icon.

           Notes specific to the use of FileMaker Server will display the FileMaker Server icon.

               Notes specific to PHP methods will display the PHP icon.

           Notes not specific to anything will display the notes icon. Notes present an interesting topic that you
           can research further on your own.

        Specific precautions that you should pay attention to. If you don’t you are bound to run into problems.

         Specific instructions for Mac OS X only.

           Specific instructions for Windows only.

                                                           3
About the Author
                       Todd Duell is the CIO of Formulations Pro, Inc. and has been creating powerful custom
                       and commercial solutions using FileMaker Pro since 1989. Todd holds an M.B.A. in
                       Technology Management, is a Certified FileMaker Pro Developer, and has been a
                       member of the FileMaker Business Alliance since 1998. Todd has published more than
                       400 technical articles, white papers, and open source databases to the scientific and
                       Formulations Pro community of more than 3,000 worldwide subscribers. In Todd’s tenure
                       at Formulations Pro since 1997, he has created more than 40 commercial databases and
                       web-based applications for numerous worldwide, multi-billion dollar companies.
                       Additionally, Todd is a regular contributor to Advisor Magazine, the industry-leading trade
                       magazine for the FileMaker Developer community, and for the FileMaker Technet
                       Resource Library at FileMaker Inc. Lastly, Todd frequently speaks at conferences and
                       seminars on topics ranging from 21 CFR 11 (electronic records and signatures) to HIPAA
compliance using FileMaker technology.

On a personal side, Todd has been an avid Triathlete for the past 23 years, competing in more than 250 races
with more than 100 top-3 age group finishes and numerous top-10 overall finishes. Todd has also finished 6
Ironman events, including the famed course at Kona, Hawaii. When he’s not training or racing, Todd can be found
playing outfield for Magic Sports — a “Major Plus” rated men’s tournament softball team. This is the highest
worldwide ranking a team can achieve. The teams that Todd has played for have played at the State
Championships and World Series of Softball for a variety of associations every year since 2000. In 2010, Magic
Sports won both the SSUSA California State Championship and the World Series. In 2011, Magic Sports placed
second at both the State and World Championships. Todd was named to the “All Tournament Team” both years,
batting an impressive 0.760 and 0.780 average respectively.

                                                        4
FileMaker Error Codes

When you create a database, scripts, and PHP web pages you are going to encounter errors. FileMaker Pro and
FileMaker Server are only going to return an error number to you. That means you’ll have to track down the error
code and figure out what to do with it. In many cases the description of the error code will be relatively
ambiguous. Therefore, it’s always handy to have a list of all the possible error codes and their descriptions. You
can also download this error code list in a FileMaker database from our web site at www.formulationspro.com.

   -1   Unknown error
    0   No error
    1   User canceled action
    2   Memory error
    3   Command is unavailable (for example, wrong operating system, wrong mode, etc.)
    4   Command is unknown
    5   Command is invalid (for example, a Set Field script step does not have a calculation specified)
    6   File is read-only
    7   Running out of memory
    8   Empty result
    9   Insufficient privileges
   10   Requested data is missing
   11   Name is not valid
   12   Name already exists
   13   File or object is in use
   14   Out of range
   15   Can't divide by zero
   16   Operation failed, request retry (for example, a user query)
   17   Attempt to convert foreign character set to UTF-16 failed
   18   Client must provide account information to proceed
   19   String contains characters other than A-Z, a-z, 0-9 (ASCII)
   20   Command/operation canceled by triggered script
  100   File is missing
  101   Record is missing
  102   Field is missing
  103   Relationship is missing
  104   Script is missing
  105   Layout is missing
  106   Table is missing
  107   Index is missing
  108   Value list is missing
  109   Privilege set is missing
  110   Related tables are missing
  111   Field repetition is invalid
  112   Window is missing
  113   Function is missing
  114   File reference is missing
  115   Menu set is missing
  116   Layout object is missing
  117   Data source is missing
                                                                      370
118   Theme is missing
130   Files are damaged or missing and must be reinstalled
131   Language pack files are missing (such as template files)
200   Record access is denied
201   Field cannot be modified
202   Field access is denied
203   No records in file to print, or password doesn't allow print access
204   No access to field(s) in sort order
205   User does not have access privileges to create new records; import will overwrite existing data
206   User does not have password change privileges, or file is not modifiable
207   User does not have sufficient privileges to change database schema, or file is not modifiable
208   Password does not contain enough characters
209   New password must be different from existing one
210   User account is inactive
211   Password has expired
212   Invalid user account and/or password; please try again
213   User account and/or password does not exist
214   Too many login attempts
215   Administrator privileges cannot be duplicated
216   Guest account cannot be duplicated
217   User does not have sufficient privileges to modify administrator account
218   Password and verify password do not match
300   File is locked or in use
301   Record is in use by another user
302   Table is in use by another user
303   Database schema is in use by another user
304   Layout is in use by another user
306   Record modification ID does not match
307   Transaction could not be locked because of a communication error with the host
308   Theme is in use by another user
400   Find criteria are empty
401   No records match the request
402   Selected field is not a match field for a lookup
403   Exceeding maximum record limit for trial version of FileMaker Pro
404   Sort order is invalid
405   Number of records specified exceeds number of records that can be omitted
406   Replace/Reserialize criteria are invalid
407   One or both match fields are missing (invalid relationship)
408   Specified field has inappropriate data type for this operation
409   Import order is invalid
410   Export order is invalid
412   Wrong version of FileMaker Pro used to recover file
413   Specified field has inappropriate field type
414   Layout cannot display the result
415   One or more required related records are not available
416   Primary key required from data source table

                                                                       371
417   Database is not a supported data source
500   Date value does not meet validation entry options
501   Time value does not meet validation entry options
502   Number value does not meet validation entry options
503   Value in field is not within the range specified in validation entry options
504   Value in field is not unique as required in validation entry options
505   Value in field is not an existing value in the database file as required in validation entry options
506   Value in field is not listed on the value list specified in validation entry option
507   Value in field failed calculation test of validation entry option
508   Invalid value entered in Find mode
509   Field requires a valid value
510   Related value is empty or unavailable
511   Value in field exceeds maximum field size
512   Record was already modified by another user
600   Print error has occurred
601   Combined header and footer exceed one page
602   Body doesn't fit on a page for current column setup
603   Print connection lost
700   File is of the wrong file type for import
706   EPSF file has no preview image
707   Graphic translator cannot be found
708   Can't import the file or need color monitor support to import file
709   QuickTime movie import failed
710   Unable to update QuickTime reference because the database file is read-only
711   Import translator cannot be found
714   Password privileges do not allow the operation
715   Specified Excel worksheet or named range is missing
716   A SQL query using DELETE, INSERT, or UPDATE is not allowed for ODBC import
717   There is not enough XML/XSL information to proceed with the import or export
718   Error in parsing XML file (from Xerces)
719   Error in transforming XML using XSL (from Xalan)
720   Error when exporting; intended format does not support repeating fields
721   Unknown error occurred in the parser or the transformer
722   Cannot import data into a file that has no fields
723   You do not have permission to add records to or modify records in the target table
724   You do not have permission to add records to the target table
725   You do not have permission to modify records in the target table
726   There are more records in the import file than in the target table; not all records were imported
727   There are more records in the target table than in the import file; not all records were updated
729   Errors occurred during import; records could not be imported
730   Unsupported Excel version (convert file to Excel 2000 format or a later supported version and try again)
731   File you are importing from contains no data
732   This file cannot be inserted because it contains other files
733   A table cannot be imported into itself
734   This file type cannot be displayed as a picture

                                                                       372
735   This file type cannot be displayed as a picture; it will be inserted and displayed as a file
736   Too much data to export to this format; it will be truncated
737   Bento table you are importing is missing
800   Unable to create file on disk
801   Unable to create temporary file on System disk
      Unable to open file. This error can be caused by one or more of the following: Invalid database name, File is closed in FileMaker
802
      Server, File is closed in FileMaker Server, Invalid permission.
803   File is single user or host cannot be found
804   File cannot be opened as read-only in its current state
805   File is damaged; use Recover command
806   File cannot be opened with this version of FileMaker Pro
807   File is not a FileMaker Pro file or is severely damaged
808   Cannot open file because access privileges are damaged
809   Disk/volume is full
810   Disk/volume is locked
811   Temporary file cannot be opened as FileMaker Pro file
813   Record Synchronization error on network
814   File(s) cannot be opened because maximum number is open
815   Couldn't open lookup file
816   Unable to convert file
817   Unable to open file because it does not belong to this solution
819   Cannot save a local copy of a remote file
820   File is in the process of being closed
821   Host forced a disconnect
822   FMI files not found; reinstall missing files
823   Cannot set file to single-user, guests are connected
824   File is damaged or not a FileMaker file
825   File is not authorized to reference the protected file
826   File path specified is not a valid file path
850   Path is not valid for the operating system
851   Cannot delete an external file from disk
852   Cannot write a file to the external storage
900   General spelling engine error
901   Main spelling dictionary not installed
902   Could not launch the Help system
903   Command cannot be used in a shared file
905   No active field selected; command can only be used if there is an active field
906   Current file is not shared; command can be used only if the file is shared
920   Can’t initialize the spelling engine
921   User dictionary cannot be loaded for editing
922   User dictionary cannot be found
923   User dictionary is read-only
951   An unexpected error occurred (*)
954   Unsupported XML grammar (*)
955   No database name (*)
956   Maximum number of database sessions exceeded (*)
957   Conflicting commands (*)

                                                                     373
958    Parameter missing (*)
959    Custom Web Publishing technology disabled
960    Parameter is invalid
1200   Generic calculation error
1201   Too few parameters in the function
1202   Too many parameters in the function
1203   Unexpected end of calculation
1204   Number, text constant, field name or “(“ expected
1205   Comment is not terminated with "*/"
1206   Text constant must end with a quotation mark
1207   Unbalanced parenthesis
1208   Operator missing, function not found or “(“ not expected
1209   Name (such as field name or layout name) is missing
1210   Plug-in function has already been registered
1211   List usage is not allowed in this function
1212   An operator (for example, +, -, *) is expected here
1213   This variable has already been defined in the Let function
       AVERAGE, COUNT, EXTEND, GETREPETITION, MAX, MIN, NPV, STDEV, SUM and GETSUMMARY: expression found where a
1214
       field alone is needed
1215   This parameter is an invalid Get function parameter
1216   Only Summary fields allowed as first argument in GETSUMMARY
1217   Break field is invalid
1218   Cannot evaluate the number
1219   A field cannot be used in its own formula
1220   Field type must be normal or calculated
1221   Data type must be number, date, time, or timestamp
1222   Calculation cannot be stored
1223   Function referred to is not yet implemented
1224   Function referred to does not exist
1225   Function referred to is not supported in this context
1300   The specified name can’t be used
1400   ODBC client driver initialization failed; make sure the ODBC client drivers are properly installed
1401   Failed to allocate environment (ODBC)
1402   Failed to free environment (ODBC)
1403   Failed to disconnect (ODBC)
1404   Failed to allocate connection (ODBC)
1405   Failed to free connection (ODBC)
1406   Failed check for SQL API (ODBC)
1407   Failed to allocate statement (ODBC)
1408   Extended error (ODBC)
1409   Error (ODBC)
1413   Failed communication link (ODBC)
1414   SQL statement is too long
1450   Action requires PHP privilege extension (*)
1451   Action requires that current file be remote
1501   SMTP authentication failed

                                                                    374
1502   Connection refused by SMTP server
1503   Error with SSL
1504   SMTP server requires the connection to be encrypted
1505   Specified authentication is not supported by SMTP server
1506   Email(s) could not be sent successfully
1507   Unable to log in to the SMTP server
1550   Cannot load the plug-in or the plug-in is not a valid plug-in
1551   Cannot install the plug-in. Cannot delete an existing plug-in or cannot write to the folder or disk
1626   Protocol is not supported
1627   Authentication failed
1628   There was an error with SSL
1629   Connection timed out; the timeout value is 60 seconds
1630   URL format is incorrect
1631   Connection failed

                                                                       375
FileMaker API for PHP Reference

One of the chief reasons why I wrote this book is because for a long time the only reference material available to
use the FileMaker API for PHP was the electronic documentation supplied with FileMaker Server. Of course, this
information is absolutely useless as a starting point to use the FileMaker API for PHP methods. However, now
that you’ve gone though all the examples in this book you may find this reference material useful. The electronic
documentation references the methods from 19 different points of view (i.e. Classes). Some methods will only
work with specific Classes and some methods will work with more than one Class. For example, you would never
tell the $fm object (FileMaker Class) to use the method getFields. The FileMaker Class is not designed to retrieve
the contents of a field. The FileMaker class is designed to define database properties, connect to the database,
and get information about the API. If you need to get information from the fields you’ll find that information using
the FileMaker_Layout Class. If this still sounds confusing, let me try to simplify Classes and methods. Don’t worry
about what the Classes mean. You don’t actually code Classes on your PHP pages, you code the methods.
Classes are simply a way to logically organize the methods and what the FileMaker API for PHP can perform.
You may find the method you need listed as part of 10 different Classes. However, the method is coded exactly
the same on your web page regardless of which Class is being used. The most important thing you need to know,
other than how to code the syntax of the method, is what the method will return to you. There are nine different
values the Methods can return:

•    Array: One or more fields or records that you can use to display information.

•    Boolean: TRUE or FALSE that you can use for trapping for errors.

•    Integer: A number such as the record count.

•    String: Text, such as the contents of a field.

•    Void: Nothing, used for methods that don’t return any results such as addSortRule.

•    FileMaker_Record: Returns an object that contains an array of information about the record.

•    FileMaker_Result: Returns an object that contains an array of information about the result.

•    FileMaker_Layout: Returns an object that contains an array of information about the layout.

•    FileMaker_Command: Returns an object that acts on a specified record or found set of records.

The reference material below will only list the methods one time with the syntax and the expected value that it will
return. The example column lists the first file where there method was used in this book. Many of the methods are
used in multiple examples. If you need more detailed in formation you can reference the documentation located
at:

FileMaker Server/Documentation/PHP API Documentation/index.html

Method                           Syntax                                          Value                 Lesson
add()                            add($Precedence, $FindRequest)                  void                  26
addError()                       addError($Field, $Rule, $Value)                 void                  N/A
addFindCriterion()               addFindCriterion($FieldName, $TestValue)        void                  3
addSortRule()                    addSortRule($FieldName, $Precedence, $Order)    void                  2
clearFindCriteria()              clearFindCriteria()                             void                  N/A
clearSortRules()                 clearSortRules()                                void                  N/A
commit()                         commit()                                        void                  9
createRecord()                   createRecord($LayoutName, $FieldValue)          FileMaker_Record      N/A
                                 Note: Same as newAddCommand
delete()                         delete()                                        FileMaker_Result      6
describeLocalValidationRules()   describeLocalValidationRules()                  array                 N/A
describeValidationRule()         describeValidationRule($ValidationRule)         array                 N/A
execute()                        execute()                                       FileMaker_Result      1

                                                              376
Method                      Syntax                                         Value               Lesson
getContainerData()          getContainerData($URL)                         string              12
getContainerDataURL()       getContainerData($URL)                         String              12
getErrors()                 getErrors($FieldName)                          array               25
getFetchCount()             getFetchCount()                                integer             N/A
getField()                  getField($FieldName, $Repetition)              string              1
getFieldAsTimestamp()       getFieldAsTimestamp($FieldName, $Repetition)   integer             35
getFields()                 getFields()                                    array               27
getFieldUnencoded()         getFieldUnencoded($FieldName, $Repetition)     string              36
getFirstRecord()            $result = $request->getFirstRecord()           FileMaker_Record    22
getFoundSetCount()          getFoundSetCount()                             integer             14
getLastRecord()             $result = $request->getLastRecord()            FileMaker_Record    21
getLayout()                 getLayout()                                    FileMaker_Layout    13
getLocalValidationRules()   getLocalValidationRules()                      array               N/A
getMessage()                getMessage()                                   string              1
getModificationID()         getModificationID()                            integer             20
getName()                   getName()                                      string              25
getParent()                 getParent()                                    FileMaker_Record    N/A
getProperties()             getProperties()                                array               N/A
getProperty()               getProperty($PropertyName)                     string              N/A
getRange()                  getRange()                                     array               N/A
getRecordById()             getRecordById($LayoutName, $RecordID)          FileMaker_Record    4
getRecordId()               getRecordId()                                  string              4
getRecords()                getRecords()                                   array               1
getRelatedSet()             getRelatedSet($TableName)                      array               8
getRelatedSetsFilters()     getRelatedSetsFilters()                        array               N/A
getRelatedSets()            getRelatedSets()                               array               N/A
getRepetitionCount()        getRepetitionCount()                           integer             N/A
getResult()                 getResult()                                    string              27
getStyleType()              getStyleType()                                 string              N/A
getTableRecordCount()       getTableRecordCount()                          integer             14
getType()                   getType()                                      string              N/A
getValidationMask()         getValidationMask()                            integer             N/A
getValidationRules()        getValidationRules()                           array               N/A
getValueList()              getValueList($ValueListName)                   string              13
getValueListTwoFields()     getValueListTwoFields($ValueListName)          array               13
hasValidationRule()         hasValidationRule($Number)                     Boolean             N/A
isAutoEntered()             isAutoEntered()                                Boolean             N/A
isError()                   IsError()                                      Boolean             1
isValidationError()         isValidationError()                            Boolean             N/A
listFields()                listFields()                                   array               N/A
new FileMaker               new FileMaker('DatabaseName', $HostSpec,       FileMaker           dbaccess.php
                            $UserName, $Password)
newAddCommand()             newAddCommand($LayoutName, $FieldValues)       FileMaker_Command   5
newCompoundFindCommand()    newCompoundFindCommand($LayoutName)            FileMaker_Command   26
newDeleteCommand()          newDeleteCommand($LayoutName, $RecordID)       FileMaker_Command   N/A
                            Note: Same as Delete()
newDuplicateCommand()       newDuplicateCommand($LayoutName, $RecordID)    FileMaker_Command   30
newEditCommand()            newEditCommand($LayoutName, $RecordID,         FileMaker_Command   7
                            $FieldValues)
newFindCommand()            newFindCommand($LayoutName)                    FileMaker_Command   3
newFindAllCommand()         newFindAllCommand($LayoutName)                 FileMaker_Command   1
newFindAnyCommand()         newFindAnyCommand($LayoutName)                 FileMaker_Command   29
newFindRequest()            newFindRequest($LayoutName)                    FileMaker_Command   26

                                                           377
Method                      Syntax                                               Value               Lesson
newPerformScriptCommand()   newPerformScriptCommand($LayoutName,                 FileMaker_Command   17
                            $ScriptName, $ScriptParameter)
numErrors()                 numErrors()                                          integer             25
setField()                  SetField($FieldName, $Value)                         void                5
setFieldFromTimestamp()     setFieldFromTimestamp($FieldName, $Timestamp)        void                N/A
setLogicalOperator()        setLogicalOperator($Operator)                        void                27
setModificationId()         setModificationId($ModificationID)                   void                20
setOmit()                   setOmit($Value)                                      void                26
setPreCommandScript()       setPreCommandScript($ScriptName, $ScriptParameter)   void                N/A
setPreSortScript()          setPreSortScript($ScriptName, $ScriptParameter)      void                N/A
setRange()                  setRange($Skip, $Max)                                void                18
setRelatedSetsFilters()     setRelatedSetsFilters($RelatedSetsFilter,            void                35
                            $RelatedSetsMax)
setResultLayout()           setResultLayout($LayoutName)                         void                27
setScript()                 setScript($Scriptname, $ScriptParameter)             void                45
validate()                  validate($FieldName)                                 Boolean             5

                                                           378
Index                                               D

A                                                   database, 26, 62-71
                                                    Date field, 85, 221, 225, 277, 284, 298
access log, 368, 369                                date_create(), 278
Accounts and Privileges, 69                         date_diff(), 278
action, 6, 61                                       dates, 102, 267, 276,
add(), 227                                          dbaccess.php, 17, 55, 74
addFindCriterion(), 87, 90, 93, 105, 110, 119,      decrement function --, 58, 173
     124, 131, 160, 166, 186, 191, 196, 227, 231,   default folders, 11, 13, 15, 16, 29
     283, 316, 376                                  delete page, 10, 105
addSortRule(), 82, 85, 227, 289, 293, 297, 376      delete portal record, 131
Admin Console Start Page, 35                        delete record, 105, 135, 179,
Adobe, 61                                           delete related record, 131
AJAX, 43, 73, 262                                   delete(), 105, 108, 136
alt_row_color CSS, 171                              die, 101
alternate background color, 171                     disiplay URL image, 140
anchor tag, 7, 339                                  display container field, 138
Apache, 11, 251, 334, 357, 361                      display image, 138
array, 43, 60                                       display related records, 115, 119
ASP, 357                                            display search results, 157
associative array, 60, 155, 304, 323                display_errors, 260
AWStats, 368                                        do while, 59
                                                    Documents folder, 201-206, 286
B                                                   DocumentsPath, 65, 205
                                                    DocumentsPathListing, 205
backspace character \, 56                           Dreamweaver, 41
bandwidth, 360                                      drop down list, 187, 213, 217
bar chart, 293                                      duplicate record, 241
BBEdit, 41                                          duplicate related records, 245
body tag, 5                                         dynamic DNS, 361
boolean, 209, 376
Boolean check box, 209                              E
Boolean1, 66
                                                    echo, 55
C                                                   edit portal record, 124
                                                    edit record, 110, 196
cache flush, 364                                    edit related record, 124
Calendar, 267                                       else, 58
CALS, 358                                           elseif, 58
carriage return, 213, 229, 321                      em tag, 6
check box, 66, 209, 213, 336                        email address, 69, 100, 102, 161, 167, 183, 236 , 319
checkdate(), 100                                    email attachments, 319
chunk_split(), 324                                  enable PHP, 23, 32, 71
Class, 376                                          end(), 146
clients, 26                                         error codes, 370
commenting code, 55                                 error log, 368
commit(), 119, 124, 131, 377                        escape character \, 56
compound search, 227                                event log, 369
concatenation, 57                                   execute(), 79, 82, 85, 87, 90, 93, 97, 100, 105, 110, 115,
connection string, 18, 74, 366                           119, 124, 131, 138, 140, 142, 149, 151, 157, 160,
ContainerBridge.php, 76, 138, 149, 231                   166, 171, 174, 179, 183, 186, 191, 196, 201, 209,
cost, 360                                                213, 217, 222, 227, 231, 239, 241, 245, 262, 267,
CRLF, 321                                                276, 280, 283, 289, 293, 297, 302, 307, 310, 316,
CSS, 5, 43, 171, 267, 280, 319                           327, 332, 336, 340, 344, 351,
cURL, 256                                           exit, 98
custom function, 52, 145, 264, 304, 313, 354        expire download links, 283
                                                    explode(), 100, 102, 145, 146, 203, 214, 218,
                                                    externally stored container field, 149
You can also read