Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts

    Question flash and remote object

    I'm using amfphp with flash and have a remote object:

    do I need to put the code

    $connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME, $connection) or die(mysql_error());

    in every function?

    PHP Code:
    <?php

    class Audio{


    define("DB_SERVER""localhost");
    define("DB_USER""audio");
    define("DB_PASS""tat");
    define("DB_NAME""audio");

        function 
    listMusic(){


            
    $connection mysql_connect(DB_SERVERDB_USERDB_PASS);
            
    mysql_select_db(DB_NAME$connection) or die(mysql_error());

            
    $q "
     select      1

    "
    ;


            
    $result mysql_query($q$connection) or $result mysql_error();

                
            
    // return $result;
            
    return $result;


        }

        function 
    checkResetPasswordKey($key){


            if (!
    eregi("^[0-9a-zA-Z]{50}$",$key)) {
                return 
    false;
            }


            
    $connection mysql_connect(DB_SERVERDB_USERDB_PASS);
            
    mysql_select_db(DB_NAME$connection) or die(mysql_error());


            
    /* Verify that user is in database */
            
    $q "SELECT * FROM tbUsers WHERE forgotPassKey = '$key' AND
    now() < forgotPassExpiry"
    ;
            
    $result mysql_query($q$connection);
            if (!
    $result || (mysql_numrows($result) < 1)) {
                return 
    false;
            }
            return 
    $result ;

        }


  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    No, just put in there once just after your DEFINES but you will need to pass in the mysql connection link identifier to the function or your queries won't run. In your case
    function listMusic($db){

    Then replace any instance of $connection in your functions to $db. Now just call it using listMusic($connection) and it will work. Do that for the rest of your functions that run mysql queries.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    nikos101 (10-20-2009)

  • #3
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    thanks mate, do I need to close the connection somewhere in the class


  • #4
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    I've done this:

    PHP Code:
    <?php
    class Audio{

    define("DB_SERVER""localhost");
    define("DB_USER""audio");
    define("DB_PASS""tat");
    define("DB_NAME""audio");

    var 
    $connection mysql_connect(DB_SERVERDB_USERDB_PASS);
            
    mysql_select_db(DB_NAME$connection) or die(mysql_error());
        

        function 
    listMusic(){
    biut I'm getting an error now:

    Parse error: parse error, unexpected T_STRING, expecting T_FUNCTION in C:\Users\Nikos\Documents\Computing\htdocs\amfphp\services\moc\Audio.php on line 4


  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Post all of Audio.php please.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #6
    Senior Coder nikos101's Avatar
    Join Date
    Dec 2006
    Location
    London
    Posts
    1,008
    Thanks
    59
    Thanked 10 Times in 10 Posts
    Thanks Aero, I managed to get rid of the errors by doing this:

    <?php
    define("DB_SERVER", "localhost");
    define("DB_USER", "audio");
    define("DB_PASS", "tat");
    define("DB_NAME", "audio");
    class Audio{


    var $connection;

    function Audio(){

    $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());

    }



  •  

    Posting Permissions

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