develooper Front page | perl.dbi.users | Postings from March 2008

Script hangs when I add WHERE clause to SQL. Not understanding 'Prepare'?

Thread Next
From:
Mark Davenport
Date:
March 26, 2008 06:56
Subject:
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;
The SQL in the second block runs fine in my MySQL query window.
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


Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About