the facts:

solaris 8 x86
perl 5005_03
DBI 1.15
DBD::Pg 0.98
PostgreSQL 7.1.1

the problem:

doing a simple SELECT query aginst a single table. If
i use interpolated SQL, it works just fine, but if i
use a bind statement, i get no results from my query.
the code i am testing with is below (the bind stuff is
commented out). Any ideas as to why the binds don't
work?

TIA

rob


the code:

====================================================

#!/usr/bin/perl

use strict;

use CGI;

use DBI;

use DBD::Pg;

my $q = new CGI;

my $field = $q->param("field");

my $text = "\'\%" . $q->param("text") . "\%\'";

my $dbname = 'foobardb';



####this is the interpolated statement, which
works####

my $sql = "SELECT * FROM widgets WHERE $field LIKE
$text";



my $dbh = DBI->connect("dbi:Pg:dbname=$dbname");



####this is the one that does work####

my $sth = $dbh->prepare( "$sql");



####this uses binds, and does not work####

#my $sth = $dbh->prepare( "SELECT * FROM demographics
WHERE ? LIKE ?");

#$sth->bind_param(1, $field);

#$sth->bind_param(2, $text);    



$sth->execute();

print $q->header("text/html"),
        $q->start_html(-title=>"RESULTS",
-bgcolor=>"#8c6b6b"),
        $q->p("Here are the results of your query:"),
        $q->p("value of field: $field"),
        $q->p("value of text: $text"),
        $q->hr;
        
while ( my @row = $sth->fetchrow_array ) {

        print $q->p("first element is: $row[0]");
        
        print $q->hr;
        
        }
        
$q->end_html;

=================================================


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Reply via email to