6 Replies Latest reply on Oct 26, 2009 6:05 PM by mewk

    Insert problems with Php Data Services


      Hi All,


      I am using Flex Data wizards to create a simple CRUD application and i am having problems adding data. It works the first time i start my application but subsequent calls to the insert fail.


      I am using FB2 Beta with MAMP. The php classes are being generated using the data wizard. i have tried commenting out mysqli_close but still it doesn't work.


      public function createDive_events($item) {


      $stmt = mysqli_prepare($this->connection, "INSERT INTO $this->tablename ( divedate, divesite, divecost, description, totalDays) VALUES ( ?, ?, ?, ?, ?)");



      mysqli_bind_param($stmt, 'ssdsi', $item->divedate, $item->divesite, $item->divecost, $item->description, $item->totalDays);






      $autoid = mysqli_stmt_insert_id($stmt);





      return $autoid;



      Any ideas, what i am doing wrong. I have tried using the update and it works only once as well, it seems that the connection to the function is lost after the first call.


      thank you,


        • 1. Re: Insert problems with Php Data Services
          mewk Level 3

          Hi Desiclimber,


          To begin with I'm not a big fan of mixing oo and procedural styles w/in the same code block (this can trip you up, but I don't think it's causing an error here).


          Secondly, I don't understand your use of statements. Prepared statements speed up the process of inserting/updating/selecting multiple queries in a row (think hundreds of insertions), but here there is only a single INSERT. If you intend to do multiple insertions on single call, then createDive_events() should take an array of objects and within the code you need to cycle through them.


          Lastly, I don't know how $this->connection is getting initialized -- perhaps that's what's tripping you up? Good luck,


          - e

          • 2. Re: Insert problems with Php Data Services
            Desiclimber Level 1

            thank you for your reply,



            the code that i have posted is what being auto generated by the php data wizard with FB2, the connection is being initialized in the constructor of the class.


            public function __construct() {

              $this->connection = mysqli_connect(












            this code works just fine during the first insert but then it doesn't get executed during the second insert. if i close the flex app and then insert something it works fine.

            • 3. Re: Insert problems with Php Data Services
              mewk Level 3



              Sorry, I've never used FB to generate the php classes. I just tried myself and confirm that the create statements only execute once successfully. This should probably be logged to jira as a bug. Will dig into the code and let you know if I find a workaround. Thanks,


              - e

              • 4. Re: Insert problems with Php Data Services
                mewk Level 3

                Ok, this is what I got.

                1. create a mysql table (`people`) with columns id (auto increment), first_name, last_name, age
                2. in the data/service panel connect to a php service, generate a php service from the database and the people table
                3. generate a form from the createPeople service call
                4. observe that in source view we have something like this:
                         protected function button_clickHandler(event:MouseEvent):void {
                            createPeopleResult.token = peopleService.createPeople(people);
                    <valueObjects:People id="people" 
                    <peopleservice:PeopleService id="peopleService"/>
                    <s:CallResponder id="createPeopleResult"/>


                If you now try to execute the code, you will find that you can only insert one person, where each successive addition silently fails.


                There is nothing really wrong with the php code (well actually since it's auto incrementing on id you should pull all id reference out of the insert statements...) rather there is a problem with the flex people object.


                If you make the following changes the code will work

                protected function button_clickHandler(event:MouseEvent):void {
                  var myPerson:People = new People();
                  myPerson.first_name = people.first_name;
                  myPerson.last_name = people.last_name;
                  myPerson.age = people.age;
                  createPeopleResult.token = peopleService.createPeople(myPerson);


                - e

                • 5. Re: Insert problems with Php Data Services
                  Desiclimber Level 1

                  cool, thanks a lot that worked. So it seems to me that there is some sort of binding created with the value object in the declaration and that gets executed only once for every operation call or something like that.

                  • 6. Re: Insert problems with Php Data Services
                    mewk Level 3

                    Filed a bug report here: http://bugs.adobe.com/jira/browse/FB-23621


                    There is a two-way binding between the value object and the text fields of the form. The value object is changing, however, the service doesn't seem to want to execute after the first call. Maybe it was designed to avoid duplicate sends and it doesn't realize the argument object has been modified. Dunno, not really sure.


                    - e