Helo to all!

Just lookin for a little direction here. Any ideas would really help me out.

We have an application that we are developing that will use a central code base (meaning all companys/users will use the same domain and code structure) to prevent versioning errors.

What I want to do is have a main database that stores user authentication information and setings for particular companies. From this database the settings are retrieved and processing continues.

I want to have the ability to store the company data in another database on potentially another server?

Is this possible?? Connect to a database for authentication then connect to another database using the information obtained from the first??

Thanks for the help!

    yea its possible...

    what have you got started thus far?

    got any code for us to toy with?

      Looking for some help so I have not started coding yet?? If you would write out the psuedocode I could figure it out from there....

        As a mock-up example.... if a username and password were sent in via a form it might look something like this:

        <?php
        
        // Localize the submitted form values:
        $username = (isset($_POST['user']) && !empty($_POST['user'])) ? $_POST['user'] : -1;
        $password = (isset($_POST['pass']) && !empty($_POST['pass'])) ? md5($_POST['pass']) : -1;
        
        // If either are not filled in, we just can't work:
        if($username === -1 || $password === -1)
            die('I just can\'t work like this.  You have to give me SOME information!!');
        
        // Connect to our authentication database
        $conn = mysql_connect('authentication.domain.com', 'authUser', 'authPass');
        if(!$conn)
            die('Hmm... seems that we can\'t connect to the mySQL server for authentication.');
        mysql_select_db('authentication', $conn);
        
        // Let's authenticate the user:
        $query = "SELECT sqlServer, sqlUser, sqlPass, sqlDBName
        FROM userAuth
        WHERE username='$username'
          AND password='$password'";
        $result = mysql_query($query);
        if(!$result)
            die('IMPERSONATOR!!! You are not who you say you are!!');
        
        // Authentication done, let's get some info for the next connect:
        $row = mysql_fetch_array($result);
        
        // Free some memory please...
        mysql_free_result($result);
        mysql_close($conn);
        
        // Now, connect to our second DB:
        $conn = mysql_connect($row['sqlServer'], $row['sqlUser'], $row['sqlPass']);
        if(!$conn)
            die('Misconfiguration!! Check the SQL info in the database.');
        mysql_select_db($row['sqlDBName'], $conn);
        
        /*
         * From this point, you could use the regular mysql_query() call
         * for any subsequent query against the second database.
         */
        ?>

        As an alternative, you can use multiple $conn variables ($conn1, $conn2, $authConn, $compConn, etc.) and have multiple mySQL connections open. Now, this isn't efficient (costs memory) but it can be done. You just have to make sure you specify which database connection you want to use when you call [man]mysql_query/man.

          Now suppose that session data was to be stored in the database. How would you store this information so it was not necessary to connect to the auth db everytime?

            What kind of session data? You mean like a session identifier? Or do you mean like authentication stuff saying that you're logged in and such?

              Well I wan to be able to store the session data in the 2nd database that way each companies session data is not floating around in the same database as the other companies.

              I just cant wrap my arms around the auth part. Since I need to connect to one database to get the DB connection information, which would involve knowing who was logged in using session data.

              So I guess I cant have my cake and eat it too!

                Okay.....

                If you have a form and a user puts their username and password in it, why do you need Session data? You can use the username and password to verify the login is correct since you're using an authentication database. Once authenticated, you can just use the retrieved SQL connection information to connect to the new database. Then all you have to do is connect to the new database, read the session information (whatever that may be) and repopulate the $_SESSION array with the old session data, updating the authentication information.

                I'm not sure what session data you're holding. That still needs to be answered. But you should still be able to look at the example I gave you above, and use that to come up with something that will work for you.

                  Write a Reply...