Welcome, Guest
  • Author Topic: Upstream??  (Read 10475 times)

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Upstream??
    « on: 02/27/03, 19:02 »
    All examples I have seen so far are retrieving data only, is it also useful for adding rows to a db, or should I still be using LoadVars for that?

    Louis Simpson

    • Server what's that
    • *
    • Posts: 25
      • View Profile
      • Email
    Re:Upstream??
    « Reply #1 on: 02/27/03, 22:21 »
    Totally you can use amfphp

    I use it here,

    http://www.irq11.com/~louie/freddyServer2/freddyServer.html


    I just pass an object in as my paramter to my remote function and manipulate there. Thats how you can update cells in the datagrid. Try picking a city and editing the first name

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #2 on: 02/27/03, 22:35 »
    You have updated it since you posted it on actionscript.org, haven't you?
    That is kind of what I want to do, but does it handle larger objects, like >20 properties?

    Louis Simpson

    • Server what's that
    • *
    • Posts: 25
      • View Profile
      • Email
    Re:Upstream??
    « Reply #3 on: 02/27/03, 22:37 »
    Probably, also why not just build a form with text fields to load a record into change them and send them back to PHP.

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #4 on: 02/27/03, 22:40 »
    I have done just that, but I also need to add new recordsets to, there is currently an addClient function, and a updateClient function.

    I thought that nailing the new one first would make the other a simple task.

    Louis Simpson

    • Server what's that
    • *
    • Posts: 25
      • View Profile
      • Email
    Re:Upstream??
    « Reply #5 on: 02/27/03, 22:44 »
    I can tell you there is really nothing to the PHP I did for that one. In fact this does it all. I could easily do a add new record, but then I would have to work on my datagrid component also.

    [script]
    class people extends PHPRemoting
    {
       function people() {
          $this->db = mysql_connect(DBHOST,DBUSER,DBPASS);
          mysql_select_db(DBNAME);
           $this->PHPRemoting();
    //        $this->_setReturnType("updatePerson","string");

       }

       function getPersonById($id) {
          return mysql_query("SELECT * from test WHERE id = ".$id);
       }   
       
       function getCityList()
       {
          $sql = "SELECT DISTINCT City from test ORDER by City";
          return mysql_query($sql);
       }
       function updatePerson($obj)
       {
          $sql = "UPDATE test set ";
          $a = array();
          foreach($obj as $key => $val) {
             if ($key != 'id' && $key != '__ID__') {
                $a[] = "$key = '".addslashes($val)."'";
             }
          }
          $sql .= implode(",", $a);
          $sql .= " WHERE id = ".$obj['id'];
          $q = mysql_query($sql);
          if(mysql_affected_rows())
          {
             return "Record updated successfully";
          
          }
          else
          {
             return "Error updating record";
          }
       }
       
       function getPeopleByCity($City, $fields) {
          $sql = "SELECT ";
          if(!is_array($fields)) {
             $sql .= "*";
          }
          else {
             $sql .= implode(",", $fields);
          }
          $sql .=  " from test WHERE City = '".$City['City']."'";
          return mysql_query($sql);
       }

    }
    ?>
    [/script]

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #6 on: 02/27/03, 22:55 »
    Looking at that I can see now I definitely have to read more.

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #7 on: 03/02/03, 22:14 »
    I modified your code to try and accomodate the inserting of a new recordset(20 properties), I know I am missing something.

    I have started to read core PHP programming, but it is taking too long.

    Code: [Select]

    function addClient($newClient){
             $sql = "INSERT INTO client ";
             $a = array();
             foreach($newClient as $key => $val) {
                //if ($key != 'id' && $key != '_ID_') {
                   $a[] = "$key = '".addslashes($val)."'";
             }
             $sql .= implode(",", $a);
             $q = mysql_query($sql);
             if(mysql_affected_rows()){
                return "Client added successfully";
             }else{
                return "Error updating record";
             }
          }


    The AS is

    Code: [Select]

    function addClient() {
       var newClient = new Object();
       newClient.companyName = CompanyName;
       newClient.businessType = BusinessType;
       newClient.contactName = ContactName;
       newClient.Position = Position;
       newClient.phoneNumberAC = PhoneNumberAC;
       newClient.phoneNumber = PhoneNumber;
       newClient.faxNumberAC = FaxNumberAC;
       newClient.faxNumber = FaxNumber;
       newClient.email = Email;
       newClient.postalAddress = PostalAddress;
       newClient.city = City;
       newClient.state = State;
       newClient.country = Country;
       newClient.postcode = Postcode;
       newClient.streetAddress = StreetAddress;
       newClient.sCity = SCity;
       newClient.sState = SState;
       newClient.sCountry = SCountry;
       newClient.sPostCode = SPostCode;
       newClient.Url = Url;
       newClient.cdrom = CDROM;
       newClient.interest = Interest;
       trace("sent request. newClient: " + newClient.toString());
       scdbservice.addClient(addClientReply, newClient);
       }
    }


    I know in a couple of weeks I will be able to work it out myself, just do not have that long.

    Cheers.

    Luke

    Louis Simpson

    • Server what's that
    • *
    • Posts: 25
      • View Profile
      • Email
    Re:Upstream??
    « Reply #8 on: 03/02/03, 23:41 »
    Well first

    [script]
            $sql = "INSERT INTO client ";
    [/script]

    should read

    [script]
            $sql = "INSERT INTO client SET ";
    [/script]



    And I am pretty sure your as should look like.

    [script]
    scdbservice.addClient(newClient);
    [/script]

    The result handler would be

    [script]
    function addClient_Result(result) {
    //do soemthing with result
    }
    [/script]

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #9 on: 03/02/03, 23:52 »
    Thanks Louis. That worked sweet.

    So the update for the 20 properties would be same as your people code? The only thin I am not sure of with that one is the line:
    Code: [Select]

    if ($key != 'id' && $key != '_ID_') {


    is _ID_  relative to the id field of your table?

    Luke

    Louis Simpson

    • Server what's that
    • *
    • Posts: 25
      • View Profile
      • Email
    Re:Upstream??
    « Reply #10 on: 03/02/03, 23:55 »
    id was my primary key, so yes you wouldn't need that. But the object I retrieved from a RecordSet Object which has that property autu set in flash.  So I was just making sure not to include that property in my SQL statement since there is not a corresponding field in the database table.

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #11 on: 03/03/03, 00:01 »
    ok got ya.  Thanks heaps.

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #12 on: 03/03/03, 02:19 »
    i have got everything working now, but I did use the reply call where you define the responder in the service call:

    Code: [Select]

    scdbservice.addClient(addClientReply, newClient);


    Otherwise I could not trigger the function I needed to acknowledge the success.

    Luke

    Louis Simpson

    • Server what's that
    • *
    • Posts: 25
      • View Profile
      • Email
    Re:Upstream??
    « Reply #13 on: 03/03/03, 02:21 »
    Weird I would have thought the way I have been doing it would have worked.
    [script]
    function addClient_Result(result) {
     //do soemthing with result
    }
    [/script]

    Where the remote function name_Result does the same thing.

    mrluke

    • Server what's that
    • *
    • Posts: 22
      • View Profile
      • thesponge.com.au
      • Email
    Re:Upstream??
    « Reply #14 on: 03/03/03, 03:51 »
    It returns in the debugger, just doesn't execute the code I wanted when I put it in the function. I guess I am doing something different.