On 9/18/08, hugh111111 <[EMAIL PROTECTED]> wrote:
>
>  I'm using sqlite for my perl cgi website but I've got a problem with the
>  following select statement...
>
>  SELECT userID FROM members WHERE userName='John' AND
>  userOccupation='Carpenter'
>
>  Yet if I input this statement from the sqlite3 command prompt it works! The
>  problem seems to be with the 'and', the following statement works fine in
>  both cgi script and from the sqlite3 prompt...
>
>  SELECT userID FROM members WHERE userName='John'
>
>  I hope somebody can help with this, I'm new to both perl and sqlite but very
>  keen on using sqlite for future projects.
>
>
>
>  here is my perl script...
>
>
>  #!/usr/bin/perl
>
>  use DBI;
>
>  my $output;
>  my $sql = "SELECT userID FROM members WHERE userName='John' AND
>  userOccupation='Carpenter'";
>
>  my $dbh = DBI->connect("dbi:SQLite:test.db", "", "");
>  my $sth = $dbh->prepare($sql);
>  $sth->execute();
>
>   while ( @row = $sth->fetchrow_array ) {
>     $output .= "@row\n";
>   }
>
>  $dbh -> disconnect;
>
>  print "Content-type:text/html\n\n";
>  print "<html><body><h1>Hello World</h1> $output </body></html>";
>
>

always bind variables. See untested code below

#!/usr/bin/perl

use DBI;
my $dbh = DBI->connect("dbi:SQLite:test.db", "", "");

my $sth = $dbh->prepare(qq{
  SELECT userID
  FROM members
  WHERE userName = ? AND userOccupation = ?
});

$sth->execute('John', 'Carpenter');

my $output;
while (my @row = $sth->fetchrow_array ) {
  $output .= join(' ', @row) . "\n";
}

$dbh -> disconnect;

print "Content-type:text/html\n\n";
print "<html><body><h1>Hello World</h1> $output </body></html>";
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to