I have a few scripts now that connect to the database like this:
I want to use db_fetch to do the connection and such, so that if I ever changed the database name for example, it would be an easy switch rather than going in and changing the name in every place where the code connects to the database. I also was just told that it's a better way to do it than my current code. Can someone help me with the syntax? I don't really understand the examples I found on CPAN, and google results weren't much clearer.
thanks...
Code:
my $dsn = "DBI:Pg:dbname=name;host=name;";
my $dbh = DBI->connect($dsn, "name", "name");
my $ord = "SELECT * FROM users WHERE id = ?";
my $sth = $dbh->prepare($ord);
$sth->bind_param(1, $emp_id);
$sth->execute;
my@result = $sth->fetchrow;
$sth->finish;
I want to use db_fetch to do the connection and such, so that if I ever changed the database name for example, it would be an easy switch rather than going in and changing the name in every place where the code connects to the database. I also was just told that it's a better way to do it than my current code. Can someone help me with the syntax? I don't really understand the examples I found on CPAN, and google results weren't much clearer.
thanks...