3 Replies Latest reply on Jan 4, 2012 10:36 AM by cmbehr

    PHP API and "undefined method" error

    cmbehr

      I have a few forms on my website that save data to FM databases using the Filemaker PHP API. They work perfectly most of the time. But sometimes most of the forms stop being able to save the form data to a new record. The error looks like this:

       

      Fatal error: Call to undefined method FileMaker_Command_Add::execute()

       

      The relevant lines of code are:

       

      $newRecord =& $fm->newAddCommand('Data_Entry', $formdata);

       

      $result = $newRecord->execute();

       

      (Data_Entry is the layout name and $formdata is an array whose keys are the field names and whose values are the data I want to save in the new record.)

       

      This is driving me crazy on so many levels! I know the Filemaker.php library is getting loaded, because the form loads fine, with valuelist data appearing properly. And I'm using "require_once" to include it, so if the file wasn't found, the script would fail there. So it can't be permissions on the API files or anything like that. It's a PHP error, so maybe it doesn't even have anything to do with Filemaker, but I'm not sure where else to look.

       

      The forms work perfectly for days at a time, then with no change to the code, suddenly fail. Once a form fails, it continues to throw the error until it suddenly starts working again, with no obvious trigger (typically a day or two later). Restarting the Filemaker server doesn't fix it. When one form fails in this manner, most of the others do too (all different databases), but one in particular has never failed. (The code is essentially the same for all.) Forms that edit records, rather than saving new ones, continue working, even when they edit records in the same database where I can't create a new record.

       

      FM Server 11 on Mac 10.6.8 & Apache. PHP 5.1.2 on a different server.

       

      I'd appreciate any suggestions where to go from here.

        • 1. Re: PHP API and "undefined method" error
          cmbehr

          Just saw on a Filemaker Support page that FMS11 requires at least version 5.3 of PHP. Could that be the problem? Why would it work most of the time but not always? What could be triggering the sporadic outages?

          • 2. Re: PHP API and "undefined method" error
            LyndsayHowarth

            Perhaps :

            - a permissions issue

            More likely:

            - another issue with your code which you haven't shown us.... eg. $formdata

             

            Whenever I get this undefined method, I can always find the problem in the code on my pages.

             

            That said, PHP 5.3 is a lot less forgiving than previous versions and finds quite a few errors (mostly insignificant) on filemaker.php or support code... particularly with dates.

             

            Perhaps your $formdata has an extraneous comma? Try eliminating all but one field from $formdata and see if it adds the record. Make sure it is a text field.

             

            I also edited one servers php configs for error reporting... as many can be ignored and skipped over.

             

            - Lyndsay

            • 3. Re: PHP API and "undefined method" error
              cmbehr

              Here's an update, in case anyone else has this problem......

               

              I continued to see sporadic failures on the server running PHP 5.1. I'm reasonably sure the problem was not related to any anomalies in input data.

               

              I implemented a temporary fix. I used PHP's "method_exists" function prior to the execute call. If the function returned false, I used a PHP redirect to transfer to a new server running PHP 5.3 and created the new record from there. (Had to transfer all the data too.) That worked every time.

               

              I've since moved the entire site to the new server. I have not seen a failure since the move.