Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl dbi question... how to use db_fetch

Status
Not open for further replies.

Mizugori

Programmer
Joined
May 21, 2007
Messages
56
Location
US
I have a few scripts now that connect to the database like this:

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...
 
What's db_fetch? There's nothing on it in the DBI docs.
 
ohhh im such a dumbass... its a component of mason. i didn't even realize that at first. this is going be more confusing than i thought...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top