Mysqli准备了在SQL中工作但不在我的应用程序中的语句

I'm trying to retrieve the most recent date out of my DB with this:

$stmt2 = $conn->prepare("SELECT reportDate FROM reports WHERE bot=? ORDER BY reportDate DESC LIMIT ?");
$limit = 1;
$stmt2->bind_param("ii", $id, $limit);
$stmt2->execute();
$stmt2->bind_result($lastSeen);

I get the error:

PHP Fatal error: Call to a member function bind_param() on a non-object

I know this usually happens when there's a syntax error in the SQL statement, but I've tried running it in phpmyadmin and it works like a charm. Any suggestion?

$stmt2 is not an object, try to var_dump() it.

LIMIT does not take any parameters from prepared statements ordinarily, hence your prepare fails. And that is why you see that error on the next call.

Also go through How to apply bindValue method in LIMIT clause? and LIMIT keyword on MySQL with prepared statement