perl help needed.
I keep getting an error in a perl script.
DBD::mysql::st fetchrow_hashref failed: fetch() without execute()
the line in question is
$resultcg=$sthcg->fetchrow_hashref;
in
<?php
sub gencookie {
# Generate a cookie for UID and update their lastlogin to current UTC.
# Returns cookie ID.
local($un) = getuser($_[0]);
local($rid) = int(rand(5) * 9234.27);
$rid = crypt($rid, \"mS\");
local($salt) = chop($rid); $salt=$salt.chop($rid);
local($rid) = int(rand(1) * 10000000);
$rid = crypt($rid, $salt);
$dbhcg=DBI->connect(\"DBI:mysql:database=$dbase;hostname=$dbhost\", $dbuser, $dbpass, {RaiseError=>1});
local($time) = time();
$sthcg=$dbhcg->prepare(\"DELETE FROM tbl_Cookies WHERE UID=\\"$_[0]\\"\");
$sthcg->execute;
$sthcg=$dbhcg->prepare(\"INSERT INTO tbl_Cookies values(\\"$_[0]\\", \\"$un\\", \\"$rid\\", \\"$time\\")\");
$sthcg->execute;
$resultcg=$sthcg->fetchrow_hashref;
$sthcg->finish;
$dbhcg->disconnect;
modlastlogon($_[0]);
return $rid;
}
?>
Anyone have any ideas ?
Mika
Wil posted this at 08:32 — 11th April 2002.
They have: 601 posts
Joined: Nov 2001
Ugh. You shouldn't call two database calls with the same session handle? That's really going to confuse things.
Anyway, the variable $resultcg - what _should_ it contain in your opinion? From what I can see you're only deleting and inserting things into your database - you're not _selecting_ anything - so how can a fetchrow_hashref contain anything if you're not selecting anything to fetch? That's basically a long winded version of your error message you're seeing.
So what is $resultcg meant to return?
- wil
yabber posted this at 19:04 — 11th April 2002.
They have: 93 posts
Joined: Dec 2001
HI Wil,
Thanks for the answer, unfortunately I don't understand very much about perl at all
All I can figure out is that when a user logs in it removes the old cookie data from the DB and inserts new cookie data, it does seem to be doing that.
I have no idea what $resultcg is meant to return or how to find out
The script is so big that it's impossible to show it all here.
hmmmm what to do next ??
Mika
Wil posted this at 08:40 — 12th April 2002.
They have: 601 posts
Joined: Nov 2001
And I have no idea to be honest! I think it's just trying to retrieve the last inserted row (in a bad way, as there is a SQL command for this). I dunno.
Have you tried commenting out or deleting the line
$resultcg=$sthcg->fetchrow_hashref;
? As is, it seems redundant to me anyway.
Try that and see how you get on.
On a more general note; the level of programming is pretty poor and sketchy. What is the program? Maybe there are better alternatives around I can help you to look up.
Cheers
- wil
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.