Posted on 2008-03-26 11:29:46-07 by sparkie
Script hangs when I add WHERE clause to SQL. Not understanding 'Prepare'?
Hi all. New to Perl and new to DBI, though not new to scripting and databases in general.
My script hangs when I try to add a WHERE clause to the SQL. This code works fine
my $sql; $sql = "SELECT * FROM images order by file_number limit 20"; $dbh = DBI->connect($dsn, $user, $password) or die ($DBI::errstr); $sth = $dbh->prepare($sql) or die $DBI::errstr; $dbh->{RaiseError} = 1; $rv = $sth->execute;

If I put a where in the SQL, the script hangs indefinitely.
my $sql; $sql = "SELECT * FROM images WHERE file_number = 1000002"; $dbh = DBI->connect($dsn, $user, $password) or die ($DBI::errstr); $sth = $dbh->prepare($sql) or die $DBI::errstr; $dbh->{RaiseError} = 1; $rv = $sth->execute;

Not sure what's going on. Can I not pass an actual value into the prepare statement? Do I have to use a placeholder? Any light shed appreciated .... as the gardener said ;-)
Mark
Direct Responses: 7463 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.