+ Reply to Thread
Results 1 to 2 of 2

Thread: switch database dynamically

  1. inge is offline Newborn member little-flashed member inge is on a distinguished road
    Join Date
    Oct 2009
    Posts
    2

    switch database dynamically

    Hi there,

    i searched a while with no solution found for the problem.
    I try to pass an argument for the database name to the php main method like this:
    PHP Code:
    var $conn;
    var 
    $database;

    function 
    protokoll_service() {
        
    $this->methodTable....
        .
        .
        
    $this->conn = new Connection("123.23..."$dbname"user""pass");
    }

    function 
    setDatabase($param) {
       if (
    $param != "") {
          
    $this->database $param;
        }
    }

    function 
    xyz..... 
    So if create the remote object in flex and call setDatabase with given
    database name the connection is not established with given db name.

    Here is the flex piece
    Code:
    private function sendRemoteObject(source:String, call:String, resulthandler:Function, faulthandler:Function, obj:Object = null):void {
                var channel:Channel = new AMFChannel(null, "http://localhost/protokoll/gateway.php");
                var chSet:ChannelSet = new ChannelSet();
                chSet.addChannel(channel);
                remote = new RemoteObject();
                remote.destination="empService";
                remote.source = source;
                remote.channelSet = chSet;
                //Test
                remote.setDatabase("test");
                //var db:Object = new Object();
                //db.name = "test";
                //remote.setDatabase(db);
                //Testend
                var op:mx.rpc.AbstractOperation = remote[call]; //works fine
                var service:AsyncToken;
                
                if(obj != null){
                    service = op.send(obj);
                }
                else{
                    service = op.send();
                }
                 service.addResponder(new mx.rpc.Responder(resulthandler, faulthandler));
            }
    The variable is passed to php but the connection is not established with the given db name. with name hardcoded it works but im not flexible

    IŽd like to use this for testeing purposes. If the user start air app with test parameter amfphp should use database with name "test" otherwise it should use default db...

    Any help would be great

    Thx

    Ingo

  2. inge is offline Newborn member little-flashed member inge is on a distinguished road
    Join Date
    Oct 2009
    Posts
    2

    Hi again,

    no one could help, so i helped myself

    HereŽs how i did it:
    The fault was that on every call of the remote method all variables get
    instantiated again, so there old value was lost.

    So i just add a line:
    Code:
    session_start();
    at top of the php file and the function setDatabase to:
    Code:
    public function setDatabase($param) {
    if ($param != ""){
    $_SESSION['database'] = $param;
    }
    else {
    $_SESSION['database'] = "default-DB-Name";
    }
     }
    So it is easy to call setDatabase("testDB") before data is transfered
    and this works great...

    Maybe somebody could use this.

    Thx

    Inge
    Last edited by inge; 28th October 2009 at 17:53.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts