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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database connection

Status
Not open for further replies.

teser

Technical User
Mar 6, 2001
194
US
My script doesnt want to connect to database.
I have installed Perl on my workstation and added the DBI and DBD-ODBC and
created a DSN for my ODBC. A regular CGI script works fine but CAN'T connect
to a database.

It keeps dying at the die area where something is wrong with the connection:
$dbh = DBI->connect('DBI:ODBC:dbname','','')

This is trying to access an Access97 db on my
Windows NT workstation.

Here is the script:

#!/usr/local/bin/perl
use CGI qw:)all);

print header,
start_html("List");

use DBI;
$dbh = DBI->connect('DBI:ODBC:dbname','','') | | die print "ERROR HERE";
$statement = "SELECT * FROM agents";
$sth = $dbh->prepare($statement);
$sth->execute;

@headings = ("Agent ID", "First Name", "Last Name", "E-mail");

print &quot;<center>&quot;, h2(&quot;Agent List&quot;),
&quot;<table border>&quot;, Tr(th([@headings]));

while (@row = $sth->fetchrow_array) {
print Tr(td([@row]));
} ;

print &quot;</table></center>&quot;, end_html;

$sth->finish;
$dbh->disconnect;
 
How about the username and password to connect. I don't see that in your connection.

Also use or die &quot;$DBI::errstr&quot;; to see if you can get a detailed error message returned.

Chad. ICQ: 54380631
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top