Thread

Posted on Wed Mar 26 13:29:46 2008 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
Posted on Wed Mar 26 13:51:27 2008 by sparkie in response to 7462
Re: Script hangs when I add WHERE clause to SQL. Not understanding 'Prepare'?
Sorry - forgot to mention - Vista SP1, MySQL 5 (latest), Perl latest.
Mark
Write a response