开发者

A simple error in perl using dbi

I have a error in my prepare statement

$sqlst = $dbh->prepare('SELECT * FROM starter_trot WHERE UserId = 2345' ) or die "Couldn't prepare statement: " . $dbh->errstr;
$sqlst->execute($userid) or die "Couldn't execute statement: " . $sqlst->errstr;
my @data;
print"hai";
while (@data = $sqlst->fetchrow_array())
{
print "**";
}

execute statement and prepare statement does not fail f开发者_StackOverflowor sure.

[WHERE UserId = 2345]This is the part it fails.when i run the query in the db it retuns values.But when i run the query through scripts it fails (But no compilation or runtime issues)what is the problem.Is it in prepare we have to give with ?(bind variables and not actual values?) ~ ~


use strict, use warnings, and when using DBI, use RaiseError. You are executing with one bind value, when you have no placeholders in your SQL statement. Sure, you should see the error message the way you have it (since PrintError is the default), but RaiseError is easier than sprinkling 'or die ...' everywhere.


The DB is likely returning the column name as upper case. Try:

$sqlst = $dbh->prepare('SELECT * FROM starter_trot WHERE USERID = 2345' ) or        die "Couldn't prepare statement: " . $dbh->errstr;
$sqlst->execute($userid) or die "Couldn't execute statement: " . $sqlst->errstr;

and I bet it will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜