I'm getting a similar error, but not consistently. It's happening in my shopping cart. Most of the time it works fine, but now and then I get a similar error (DBD::mysql::st fetchrow_hashref failed: fetch() without execute()).
Here's my insert statement (personal data obliterated):
INSERT INTO orders (
firstname,
lastname,
email,
dayphone,
altphone,
addr1,
addr2,
city,
state,
zip,
country,
cctype,
ccnum,
cvv,
ccexpire,
`shipto-firstname`,
`shipto-lastname`,
`shipto-email`,
`shipto-dayphone`,
`shipto-altphone`,
`shipto-addr1`,
`shipto-addr2`,
`shipto-city`,
`shipto-state`,
`shipto-zip`,
`shipto-country`,
instructions,
couponid,
cartid,
gift,
giftmessage,
date
)
VALUES (
"Rrrrrr",
"Rrrro",
"rrrrrrds@aol.com",
"555-555-5555",
"555-555-5555",
"7054 N Train Track Ave",
"",
"Albany",
"NY",
"",
"999",
"AmEx",
"333333333333333",
"4444",
"01/2050",
"Rrrrrr",
"Rrrro",
"rrrrrrds@aol.com",
"718-555-5555",
"718-555-5555",
"7054 N Train Track Ave",
"",
"Albany",
"NY",
"",
"",
"",
"",
"5lK3WBbPfr2J/QLTiKOO7w",
"",
"",
FROM_UNIXTIME(1171046619)
)
This actually inserts a row successfully. Then I try to get the id form the auto increment column: SELECT LAST_INSERT_ID() as newid. This fails.
Basic insert code ($query is the above insert statement):
my $dbh = Mysql->connect($host, $dbname, $username, $password);
my $sth = $dbh->query($query) ;
if (my $errmsg = $dbh->errmsg() ) {
print "Error: $errmsg<br>\n$query<br>\n" if ( !$noerrmsg ) ;
return 0 ;
}
else {
# Return the new id
$query = "SELECT LAST_INSERT_ID() as newid";
my $sth = $dbh->query($query) ;
my %row = $sth->fetchhash ;
print "<!-- newid: $row{'newid'} -->\n";
return $row{'newid'} ;
}
When the error does happen, $row{'newid'} == 0, but, as I mentioned, the row has been inserted! Note the value of the cartid ("5lK3WBbPfr2J/QLTiKOO7w"). If I forces the browser to get a new cartid, the process will then complete without errors. I tested the / in the cartid with a different string, and didn't get an error.
I suppose I should be checking for errors after attempting to get the new id.