I am updating a row in a table, and trying to return the updated row, as per this SO answer.
My code is the following:
$sql = \"SET @update_id := \'\
You're right about getting the exception SQLSTATE[HY000] for $stmt->rowCount();
The problem is, you cannot fetch an UPDATE query because these queries simply don't return values. To circumvent this, use rowCount().
As written in the PHP documentation, PDOStatement::rowCount() returns the number of rows affected by a DELETE, INSERT, or UPDATE statement.
Check out this example.
prepare('UPDATE ... PICNIC');
$update->execute();
/* Return the number of rows affected */
echo $updateCount = $update->rowCount();
?>