1 Reply Latest reply on Sep 9, 2016 7:31 PM by chiweez

    Unable to connect to FileMaker database with PHP

    neeeeet

      Hi all,

       

      I have been trying to establish a connection between FileMaker 12 and the PHP API but the script keeps returning "Not Connected", and the message "Communication Error: (22) The requested URL returned error: 404 - This can be due to an invalid username or password, or if the FMPHP privilege is not enabled for that user."

       

      I have double-checked to make sure the spellings of the username and password are correct, and Full Access has already been administered to the user for the FMPHP Privilege.

       

      This is my script:

       

      //======================================================================

        //CONNECT TO DATABASE AND CHECKING CONNECTION THROUGH A FUNCTION.

      //======================================================================

       

       

        //Populating the arguements

        $booIsFMDBConnected = IsFMDBConnected(true, 'database', 'hostsite', 'username', 'password');

       

       

        If($booIsFMDBConnected){

        //===================

        //Database is Connected

        //===================

        echo "Connected";

        } else {

        //======================

        //Database is Not Connected

        //======================

        echo " Not Connected";

        }

       

       

        function IsFMDBConnected($booVerbose, $strDatabase, $strHostspec, $strUsername, $strPassword) {

        //==========

        //Initialisation.

        //==========

       

        $fm =& new FileMaker($strDatabase, $strHostspec);

        //$fm->setProperty('database', $strDatabase);

        //$fm->setProperty('hostspec', $strHostspec);

        $fm->setProperty('username', $strUsername);

        $fm->setProperty('password', $strPassword);

        $connected = $fm->listLayouts();

       

       

        //==================

        //Return the Result.

        //==================

        If(FileMaker::isError($connected)){

        //======

        //Error.

        //======

        $booIsFMDBConnected = false;

       

        If($booVerbose) {

        //=============

        //Verbose Mode.

        //=============

        echo "<br>" . $connected->message . "<br>";

        }

       

        } else {

        //=========

        //No Error.

        //=========

        $booIsFMDBConnected = true;

        }

       

        return $booIsFMDBConnected;

       

        }

       

       

      The script seems to be recognising the hostspec but not the database, username or password. I don't know why this is so. Does anyone know how to get the connection to work? Any help would be greatly appreciated, thank you.

        • 1. Re: Unable to connect to FileMaker database with PHP
          chiweez

          For me, this usually means I didn't configure something right at the FM level (permissions, PHP enabled, privilege sets, etc.)

           

          Try using a bare bones connection script to weed out any syntax issues. Hit just that .php page with your browser (no redirecting).

           

          I use the following:

           

          <?php

          require_once ('FileMaker.php');

           

          // Replace DB, HOST, USER, PASS values with your own

          $fm = new FileMaker(DB, HOST, USER, PASS);

           

          $connected = $fm->listLayouts();

          if(FileMaker::isError($connected)){

              echo "Unable to Connect to Database";

          } else {

              echo "Connected";

          }

          ?>

           

          I did notice the following in your script, not sure if that would cause an issue:

           

          $fm =& new FileMaker($strDatabase, $strHostspec);

           

          why the "&" sign?

           

          If the above script doesn't work, you'll need to look at your configuration setup again.

           

          Hope that helps.