LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-23-2005, 01:16 PM   #1
silhoutte
LQ Newbie
 
Registered: May 2005
Location: Melb
Posts: 8

Rep: Reputation: 0
Need help with database perl


This is a "simple" perl that I made to access a database called "zoo". But it seems that it can't work. Is there an expert here to help a newbie like me? Thanks a lot

#!/usr/bin/perl
# A simple perl script to access the animal table in the ZOO database
use Pg;
$dbmain = "zoo";
$conn = Pg::connectdb("dbname=$dbmain");
# check if database connection was successful?
die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status;
print "connected to $dbmain\n";
# Select Animals and display them
$sql = "SELECT * FROM animal WHERE cageno = 143";
$result = $conn->exec($sql);
# check if sql query executed successfully?
die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus;
print "select from table: $sql\n\n";
# show a list of the database table field names from resulting query
print $result->fname(0);
for ($k = 1; $k < $result->nfields; $k++) {
print ",", $result->fname($k);
}
print "\n";
# display the data returned from the above query executed
while (@row = $result->fetchrow) {
print " ", join(",", @row), "\n";
}
 
Old 05-23-2005, 01:59 PM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
I'm not seeing anything immediately wrong; you've got a lot of debug statements in there - which ones print out? i.e. where does the program fail to work? Are you getting any error messages that might help point us in the right direction?

The more information you can give, the more helpful we can be
 
Old 05-23-2005, 10:34 PM   #3
glimmy
Member
 
Registered: Apr 2005
Location: Minnesota
Distribution: slackware
Posts: 54

Rep: Reputation: 15
also try adding

edit:use warnings;

in your code. It may catch something.

Last edited by glimmy; 05-23-2005 at 11:45 PM.
 
Old 05-23-2005, 11:26 PM   #4
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
Did you mean 'use warnings'? Because yup, that would definitely help also.
Alternatively, '#!/usr/bin/perl -w' can help too (esp. if you've got an older version of perl). See here for a better explanation.
 
Old 05-24-2005, 12:12 AM   #5
silhoutte
LQ Newbie
 
Registered: May 2005
Location: Melb
Posts: 8

Original Poster
Rep: Reputation: 0
That's the problem. Gee ... my tutor is checking me now >.<

Undefined subroutine &Pg::connectdb called at /var/www/cgi-bin/zoo.pl line 6.

Help plz, thx
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Snort database: Closing connection to database "" Homer Glemkin Linux - Security 2 07-14-2005 07:58 PM
Import Database Function Script Using Perl?? domquem Programming 3 01-13-2005 10:05 AM
How to interact with MYSQL database from within perl program Bassam Programming 5 02-26-2004 06:00 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 09:09 PM
Perl and Database formats. CragStar Programming 6 08-11-2002 04:05 PM


All times are GMT -5. The time now is 09:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration