So then I create a script like so:
$database = "foo"; require '/home/share/jdb.cgi'; # now I can do whatever with $dbh..
This may not seem like the best way to do it (and may not be ;)), but I have two web servers & two different directories and I don't want to work on CGI scripts in one, test and get it ready and then move it over to production and have to remember to switch something (such as if I had a subroutine to change a parameter).
I hope this makes sense so far. Ok, so the problem is whenever my script on the development server updates the database, it's updating the production database server (not the DSN it was given, which would be port 3308, a development db server that has a different datadir, etc). I debugged & found that the DSN for the development server was being provided correctly for a script that was within the "site-dev" path ... boggles me as to what could be wrong.
Thanks in advance for any help! :)
Jason
Here's the script:
use DBI; my ($package, $filename) = caller; #my ($dsn); # if it's the dev site, return the Dev DSN, otherwise, return # the production DSN. if ($filename =~ /sites-dev/) { # it's the dev site $dsn = "DBI:mysql:database=$database;port=3308"; } else { # it's the production site $dsn = "DBI:mysql:database=$database;port=3306"; } $dbh = DBI->connect($dsn, "perlscript", "passboy"); 1;
In reply to Centralized DSN Switch Script (MySQL) by Purdy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |