Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Accesing a database from different sites

by kidd (Curate)
on May 16, 2003 at 20:15 UTC ( #258754=perlquestion: print w/ replies, xml ) Need Help??
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:

  • Solution #1: I thought than maybe I can download the database from "site1" and then upload it to "site2". This would be the right solution and an extremely easy one if it wasn't for one problem: the database in "site1" updates itself at least once a day. So the thought of having to do this every day is out of the picture.
  • Solution #2: After thinking for a while it came to me that maybe they could be a way to access a database from another site, so I could set the CGI's in "site2" to accessthe database in "site1", that way I could only use 1 database.

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
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: 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 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://258754]
Approved by cciulla
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-12-29 00:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls