2 Replies Latest reply on Feb 24, 2011 1:43 PM by D Baron

    Zend AMF Data Service Return Problem

    D Baron Level 1

      Hi Folks,

       

      I am working with FB4 and Zend AMF/PHP and MySQL.  I began integrating the PHP stuff using the great article by Mihai Corlan called 'Working in Flash Builder 4 with Flex and PHP.  I followed all the steps exactly, aside from creating my own app-specific PHP classes and functions, etc...  I 'hooked up' the Zend stuff just like the article, created a text datagrid, just like the article, and viola!, it worked.  I then tweaked it a bit and interwove it into my 'real' component.  So far, so good.

       

      Then I created a second PHP class with a different 'get data' type of function.  It queries a different table in MySQL, but is essentially the 'same' as the query/function in the initial PHP class.

       

      In FB, in the Data Services window, I choose the 'Connect to Data/Services' function, just like the first time.  I then find/select my PHP class file and FB 'interrogates it' enough to show me the function that exists in the class.  I 'finish' the operation and it adds a new 'service' to the list of services in that window.  Again, so far, so good.

       

      The problem comes when I try to 'test' the service or 'configure return types' (which basically requires a 'test' operation anyway).  I can enter the 'input' params just fine, but when I try to execute the call, I get the following error:

       

      InvocationTargetException:There was an error while invoking the operation. Check your operation inputs or server code and try invoking the operation again.

      Reason: An error occured while reading response sent by server. Try encoding the response suitably before sending it. e.g. If a database column contains UTF-8 characters then use utf8_encode() to encode its value before returning it from the operation.

      I don't know where to go after this.  Again - the 2nd PHP class is essentially identical to the 1st.  The function in it is essentially identical, differing only by the input params, the name of the function and the actual SQL it sends to MySQL.  There is no special text, no special characters, no image stuff, nothing.  I do not 'encode' the results of the function in the first class - in fact the code in the second class is practically identical to the first.  I do not know what the error is talking about.  My guess is that it's more of a generic message.

       

      I can debug the PHP code just fine from within a seperate instance of Eclipse.  The function runs/returns just fine - an array of PHP-defined objects (simple strings).

       

      Any insights or advice would be welcomed.   Thank you,

       

      -David Baron

        • 1. Re: Zend AMF Data Service Return Problem
          Jorge Raimundo Level 2

          Hi!

           

          This must be related to the fact that you have UTF-8 characters in you database and they might not be correctly handled by MySQL or Apache servers.

           

          Make sure your apache configuration has

           

          AddDefaultCharset UTF-8

           

          and also check your mysql config file to see if you have

           

          character-set-server=utf8
          default-collation=utf8_unicode_ci

           

          Also check the collation of the database and tables.

           

          Hope it helps.

          Jorge

          • 2. Re: Zend AMF Data Service Return Problem
            D Baron Level 1

            Thank Jorge, but that was not the issue, though, it may be related.

             

            I checked the mySQL my.ini file, and there was already an entry for:

            [mysql]

            default-character-set=utf8

             

            I added the 'default-collation=utf8_unicode_ci', like you suggested, but that didn't do anything.

             

            I checked the Apache httpd.conf file, and added the following line 'under' the "DefaultType text/plain" line:

            AddDefaultCharset UTF-8    but that did not do anything.

             

            I checked my mySQL database, all the tables involved.  They were already at UTF-8 (default).  However, some of the 'varchar' columns were defined as 'latin 1-default collation'.   I changed them all to utf-8 (default table collation), but that did not help either.

             

            Finally, I found the problem, though I don't really know if it is "my" problem, or ZendAMF's problem, or Adobe's problem.

             

            It turned out that 'some' of my data had a 'bad' character in it.  Specifically, I had 'copied and pasted' some data from MS Word into mySQL Workbench.  Some of the data included the 'elipsis' character - you know, when you type "..." (dot dot dot) in MS Word, it replaces the three periods with a single elipsis character.  Although PHP could easily query and assemble this data into a nice object array, I noticed that that character showed up (in PHP's debugger) as a 'box' character, meaning "bad character".  Thus, I guess, Zend AMF and/or FlashBuilder could not 'bring over' and/or deal with this type of character.  As soon as I replace the few instances of that character with three periods, everything began to work perfectly.

             

            So... what to do about this?  I thought I was through with silly encoding/decoding of data when I left JavaScript and HTML behind in moving to FlashBuilder technology.  Am I really going to have to worry about this kind of thing?  Or might this be a bug/deficiency somewhere in the stack?

             

            Thanks for your help,

             

            -David