kidd has asked for the wisdom of the Perl Monks concerning the following question:

Hello:

Currently I have a client's site working with a database driven user managament.

I use the DBI and the DBD::mysql modules to work around with MySQL database.


Everything was OK until yesterday when my client had an idea, he wanted to open a new site with different tools, but he wants some users in "site1" to be able to access "site2" with all the profile information, etc.

When presented with this idea, two solutions came to my mind:

Hurray!!! Im a smart person...am I?

That's what takes me here, I could use some ideas or comments to help me solve my problem from all you perl monks of the world.

THANKS IN ADVANCED FOR ANY HELP

  • Comment on Accesing a database from different sites

Replies are listed 'Best First'.
Re: Accessing a database from different sites
by grep (Monsignor) on May 16, 2003 at 20:34 UTC
    but he wants some users in "site1" to be able to access "site2" with all the profile information, etc.

    Well this is the big question. Does he want all or some?

    If you want all the user info then yes accessing a remote database would be your answer.

    To do this just create 2 Database handles:

    my $dbh = DBI->connect('DBI:mysql:database=dbname;host=localhost','use +r','pass'); my $dbh_user DBI->connect('DBI:mysql:database=userdb;host=remote','use +r','pass');

    Even better use Class::DBI. You'll be able to hide all the ugliness of having 2 separate databases. Just create 2 unique DBI classes to inherit from.

    grep
    Mynd you, mønk bites Kan be pretti nasti...

Re: Accesing a database from different sites
by shemp (Deacon) on May 16, 2003 at 20:31 UTC
    the DBI module allows you to specify a host machine in the DBI::connect() method. With Mysql, the first param to connect includes the options host, such as
    ... my $db_handle= DBI->connect("DBI:mysql:my_table:10.100.100.100", " +user", "pass", ...) or die; ...
    Now, this assumes that you have set up the Mysql user permissions correctly...
Re: Accesing a database from different sites
by phydeauxarff (Priest) on May 16, 2003 at 21:15 UTC
    Check out my answer to a previous mySQL question about setting up a database connection.

    That code will work fine for you, all you need to do is change "localhost" to the actual host you are trying to connect to.

    You will also need to make sure any firewalls you are going through allow port 3306, or if not...you can change that as well.

    Enjoy!

Re: Accesing a database from different sites
by CountZero (Bishop) on May 16, 2003 at 23:04 UTC

    If there is a heavy load on the site then two databases are better than one.

    You can always "slave" one database to the other so that all updates to the "master" database get automatically replicated into the other.

    Mind you, this means that the second ("slave") database cannot be updated directly: all updates must be made to the first ("master") database, to be replicated through the replication system.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law