I suspect it's in the way you're setting up your query, but you didn't
show that part?  Try this:

my $sql = 'SELECT m_id FROM machines WHERE hostname = ?';
my $host = 'torn.arlut.utexas.edu';
my $sth = $dbh->prepare($sql);

$sth->execute($host);

while (my $m_id = $sth->fetchrow_array()) {
        print $m_id, "\n";
        }

Does that go any better?

On Wed, 12 Mar 2003, Jay G. Scott wrote:

> 
> Greetings,
> 
> My code follows.  Should be enough for some bright person to figure
> out what I'm doing wrong.  To me, it all looks fine.
> 
> 
> #!/usr/bin/perl
> 
> use DBI;
> use Pg;
> use Getopt::Std;
> 
> $DBSERVER="torn.arlut.utexas.edu";
> $USERNAME="postgres";
> $PASSWORD="";
> $dbh = DBI->connect("DBI:PgPP:database=test;host=$DBSERVER", $USERNAME, $PASSWOR
> D)
>     or die "Can't connect to database: $dbh->errstr\n";
> 
> 
> #-------------------------------------------------------------------------------
> $command = "SELECT m_id FROM machines WHERE hostname = '$hostname';";
> print "attempting\n\t$command\n\n";
> my $sth = $dbh->prepare( $command );
> 
> print  "what is sth?  $sth\n";
> $sth->execute
>     or die "Unable to execute query: $dbh->errstr\n";
> #-------------------------------------------------------------------------------
> 
> Here's what happens when I run it:
> attempting
>         SELECT m_id FROM machines WHERE hostname = 'torn.arlut.utexas.edu';
> 
> what is sth?  DBI::st=HASH(0x287654)
> DBD::PgPP::st execute failed: ERROR:  parser: parse error at or near "," at 
> character 138
> Unable to execute query: DBI::db=HASH(0x286da8)->errstr
> 
> 
> As you can see, I stupidly tried to print $sth, hoping for something
> illuminating.  Anyway, I can't see what's wrong.  I don't have a comma
> at all, and the query isn't 138 characters anyway.  This feels a little
> like an unterminated string, but I thought perl handled that.  (I've
> never had to supply a null in any other of my perl stuff.)  So, to me,
> I've done it right.  If I get into the database via
>       psql thingy
> and cut and paste the query, it works.
> 
> What am I missing?  (I've never gotten this to work.)
> 
> j.
> 
> -- 
> Jay Scott             512-835-3553            [EMAIL PROTECTED]
> Head of Sun Support, Sr. Operating Systems Specialist
> Applied Research Labs, Computer Science Div.                   S224
> University of Texas at Austin
> 

Reply via email to