Re: perl and postgresql

From: douggorley(at)shaw(dot)ca
To: "Sugrue, Sean" <sean(dot)sugrue(at)analog(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: perl and postgresql
Date: 2003-03-17 16:55:11
Message-ID: 19195918d2ff.18d2ff191959@shaw.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

----- Original Message -----
From: "Sugrue, Sean" <sean(dot)sugrue(at)analog(dot)com>
Date: Monday, March 17, 2003 8:39 am
Subject: [NOVICE] perl and postgresql

>
>
> I am trying to execute the following query within perl
>
> #!/usr/local/bin/perl
>
> use DBI;
>
> $prod='stdf';
>
>
> $dbh = DBI-
> >connect("dbi:Pg:dbname=database;host=mink;port=0000","username","password");
> $sth = $dbh->prepare("select * from filestatus where fileformat =
> $prod");if( defined($sth)){
>
> $sth->execute;
> #for when model numbers are available
> while (@devices = $sth->fetchrow){
> ($product,$spec_key)=(at)devices;
> print"product = $product and speckey = $spec_key \n"; }
> }
>
> i***************************************
> it works if you put a literal value of 'stdf' for $prod
> but it fails when I try to use a variable.
>
> Another point is if it were an integer the variable would work.
>
> Question: How can I get this to work. I've used q// qw// qq// qx//
>
> Sean
>

Try using placeholders.

$prod='stdf';
$sth = $dbh->prepare("select * from filestatus where fileformat = ?");
$sth->execute( $prod );

Doug Gorley | douggorley(at)shaw(dot)ca

Browse pgsql-novice by date

  From Date Subject
Next Message Nabil Sayegh 2003-03-17 20:28:24 Re: 'UNIQUE'
Previous Message Sugrue, Sean 2003-03-17 16:39:53 perl and postgresql