9 Replies Latest reply on Sep 27, 2011 1:49 AM by kokorito

    need advise @ Dummy level please :) Object Orientated Functions

    whitefinger

      Ok so i have created my site in FLASH CATALYST and it looks great and i have created my database in MYSQL and using WAMP to serve the data and of course now writing the code in FLASH BUILDER 4.5

       

      Anyway so Flash Builder created a list of object oriented functions inorder to be compatible with flash builder and mysql and so far i have managed to bodge my way through it

       

      But i was wondering if anyone has seen a website that would be able to explain it all better to me as every site i find scares me or perhaps you might have some thing to say that will help in my understanding

       

      See this function works for me to get all Country and Country codes from the database

       

       

      public function getAllCountryCodes() {
      
              $stmt = mysqli_prepare($this->connection, "SELECT ID, country, CountryCodes  from $this->tablename1 ORDER BY id");        
              $this->throwExceptionOnError();
              
              mysqli_stmt_execute($stmt);
              $this->throwExceptionOnError();
              
              $rows = array();
              
              mysqli_stmt_bind_result($stmt, $row->ID, $row->country, $row->CountryCodes);
              
              while (mysqli_stmt_fetch($stmt)) {
                
                $rows[] = $row;
                $row = new stdClass();
                mysqli_stmt_bind_result($stmt, $row->ID, $row->country, $row->CountryCodes);
              }
              
              
              mysqli_stmt_free_result($stmt);
              mysqli_close($this->connection);
          
          
          
              return $rows;
          }
      

       

      and so i must understand something inorder to write it

       

      But this one keeps giving me errors so i assume it must be due to a lack of understanding

       

       

      public function updateClients($item) {
          
              $stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET random=? WHERE ID=? AND Town=?");        
              $this->throwExceptionOnError();
              
              mysqli_stmt_bind_param($stmt, 's', $item->random);        
              $this->throwExceptionOnError();
      
              mysqli_stmt_execute($stmt);        
              $this->throwExceptionOnError();
              
              mysqli_stmt_free_result($stmt);        
              mysqli_close($this->connection);
          }   
      

       

       

      So im calling this in Flash Builder "updateClients(random, ID, Town);" and im just getting error after error sorry to ask but i dont know if im just putting the wrong thing into google!

        • 1. Re: need advise @ Dummy level please :) Object Orientated Functions
          whitefinger Level 1

          Any way this is what im using at the moment and im getting this error? 

          "Warning: Attempt to modify property of non-object in C:\wamp\www\index-debug\services\CustomerService.php on line 54 any idea's"

           

          line 54 is this

          mysqli_stmt_bind_param($stmt, 'sss', $item->rate, $item->id, $item->town);

           

           

          public function updateClients($item) {

             

                  $stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET random=? WHERE id=? AND town=?");       

                  $this->throwExceptionOnError();

                 

                  mysqli_stmt_bind_param($stmt, 'sss', $item->rate, $item->id, $item->town);       

                  $this->throwExceptionOnError();

           

                  mysqli_stmt_execute($stmt);       

                  $this->throwExceptionOnError();

                 

                  mysqli_stmt_free_result($stmt);       

                  mysqli_close($this->connection);

          • 2. Re: need advise @ Dummy level please :) Object Orientated Functions
            whitefinger Level 1

            and if i do this

             

            public function updateClients($item) {

               

                    $stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET random=? WHERE id=? AND town=?");       

                    $this->throwExceptionOnError();

                   

                    mysqli_stmt_bind_param($stmt, 'sss', $random, $id, $town);       

                    $this->throwExceptionOnError();

             

                    mysqli_stmt_execute($stmt);       

                    $this->throwExceptionOnError();

                   

                    mysqli_stmt_free_result($stmt);       

                    mysqli_close($this->connection);

             

             

             

            it returns void and doesnt update random to the database!

            • 3. Re: need advise @ Dummy level please :) Object Orientated Functions
              whitefinger Level 1

              The horrible thing is this code use to work but after changing versions of flash builder i found my self startting again with the code as the new flash builder couldnt find the project! but now i just realise that another function that inserts into the database is also not working so it would seem that i have left some thing out!

               

              Any help please

              • 4. Re: need advise @ Dummy level please :) Object Orientated Functions
                kokorito Level 4

                you pass in $item to the method but dont use it

                shouldnt it be $item->town and $item->id etc.

                • 5. Re: need advise @ Dummy level please :) Object Orientated Functions
                  whitefinger Level 1

                  And you are so right

                  But i had already tried that but still with error but know that you have confirmed it i will keep with that thanks

                   

                  But unfortunatly my problems have now got worse as i have now tested the function in flash builder "TEST OPERATION" and it worked! So i then tested my code on my site using trace statements and it all seems to work but the mysql database doesnt update witch is really anoying  

                   

                  protected function button2_clickHandler(event:MouseEvent):void

                              {

                                 var Clientid:int = clientid.text;

                                 var number:int = random.text;

                                  var    plusOne:int = 1;

                                  var ary:Array;

                                  var random:int = (number+ plusOne);

                                  ary =[random, Clientid];

                                  customerService.updateClients(ary);

                                  trace(ary)

                              }

                   

                  public function updateClients($item) {

                         

                          $stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET random=? WHERE ID=?");       

                          $this->throwExceptionOnError();

                         

                          mysqli_stmt_bind_param($stmt, 'ii', $item->random, $item->ID);       

                          $this->throwExceptionOnError();

                   

                          mysqli_stmt_execute($stmt);       

                          $this->throwExceptionOnError();

                         

                          mysqli_stmt_free_result($stmt);       

                          mysqli_close($this->connection);

                      }  

                   

                  When i test it in console all the values in trace come up, when i test it in network monitor the request looks good but the response says error!!!! but as i said when i test it in "TEST OPERATIONS" it updates to the database, the error i get back from response in network mode is {Fault code=Client.Error.DeliveryInDoubt, Fault string=Channel disconnected, Fault detail=Channel disconnected before an acknowledgement was received, Destination=CustomerService} which doesnt tell me much any help please

                  • 7. Re: need advise @ Dummy level please :) Object Orientated Functions
                    whitefinger Level 1

                    Well according to the internet to solve my problem:

                     

                    To solve this problem make sure that:

                    • Your Adobe Flex function parameters and PHP function parameters are of the same number.
                    • The parameters of your Adobe Flex function are in the same order with its PHP function counterpart.
                    • All the Adobe Flex function parameters are of the same data type with their PHP function parameters counterpart.
                    • You assign a default value to the optional parameters in the PHP function.
                    • You pass a value to the parameters that are not optional.
                    • Finally, your SQL statements should be syntactically correct.

                     

                    But as far as i can see they are

                    • 8. Re: need advise @ Dummy level please :) Object Orientated Functions
                      whitefinger Level 1

                      Ok well i went to bed for an hour and came back to it! i changed the array to an object and it all worked!!! is that the way its ment to be? or is my code just weird

                      • 9. Re: need advise @ Dummy level please :) Object Orientated Functions
                        kokorito Level 4

                        you could have used $item['ID'] and $item['random'] if $item is an array