7 Replies Latest reply on Nov 25, 2008 3:39 PM by rtalton

    Help with Flex - PHP - and SQL Server

      Good afternoon,

      I have been working on this problem for over a week and am at my wit's end. I am trying to create an application that will allow me and my fellow statisticians to share code easily. The technologies at my disposal are Flex, PHP and SQL Server 2005. The web server is IIS. I have downloaded and installed the PHP driver for SQL Server 2005 and am able to query the database and generate XML. The problem I'm having is that I can't return the XML from PHP to Flex.

      If I execute the php code in a web browser and view the source, it looks like XML. I can then cut and paste the exact same code into an xml file and read it in from the harddisk and the tree will populate. Can anyone please help me? I don't have flex builder so I it's hard for me to use trace and view what is going on.

      Thanks in advance,

      Eric Graves
        • 1. Re: Help with Flex - PHP - and SQL Server
          rtalton Level 4
          yeah, you really need Flex Builder for debugging...
          Maybe instead of:

          You shouldn't have to include the Root element when the resultFormat="e4x".
          • 2. Re: Help with Flex - PHP - and SQL Server
            Methylparoben Level 1
            Thanks for the suggestion. I have tried every permutation of e4x path notation I can think of. You're right, you're not supposed to need the root level as that's supposed to be returned in the result. So you should only need to reference first level after the root. When I do this and launch the .SWF I get a completely empty tree.

            I think the problem lies somewhere in my understanding of what format Flex needs returned from a HTTPRequest. It's my understanding that it just needs to be XML. As far as I can tell, that's what I'm sending it. On the PHP side, does it have to be cast a special way? Everything I've seen just shows people using ECHO to output the XML data.
            • 3. Re: Help with Flex - PHP - and SQL Server
              rtalton Level 4
              Your data from PHP is fine. I used it as-is and had no problems.

              See it here:

              source view is enabled so you can see what I did.
              Hope this helps.
              • 4. Re: Help with Flex - PHP - and SQL Server
                Methylparoben Level 1
                Thank you for taking the time to assist me. I have been able to reproduce what you have created with great success, but only when I copy and paste the PHP output to a file on my harddisk and then read in the file with Flex. My aim is to have the tree built dynamically from the database based on the XML that PHP is supposed to return.

                It seems the disconnect then is in the HTTPServiceRequest and PHP. Because even though the PHP output is the exact same XML file you used in your demonstration, it fails to populate the tree in Flex. Any further assistance you can provide is greatly appreciated.
                • 5. Re: Help with Flex - PHP - and SQL Server
                  Methylparoben Level 1
                  Looking at your code again I see yo have a result function that doesn't do anything. In my code I don't have a result function at all which makes me wonder if something is needed in order for the request to work. I will try using your code tomorrow at work and let you know. Thanks again!
                  • 6. Re: Help with Flex - PHP - and SQL Server
                    rtalton Level 4
                    the result fhandler is not necessary; I only included it so I could put a line break there and debug the app and see the XML. I use the result handler because it's often cleaner to handle the result there instead of assuming the data was returned ok from the HTTPService call.
                    • 7. Re: Help with Flex - PHP - and SQL Server
                      rtalton Level 4
                      One more thing...
                      Add an fault handler to your HTTPService tag:
                      id="RPCVarDBXML" resultFormat="e4x"
                      ... and in the fault handler, an Alert.show window with the details, like:
                      public function showFaultEvent(event:FaultEvent):void {
                      // Handle service fault.
                      Alert.show(event.fault.faultString, "Error");

                      You may find the answer in the fault event.