Despite the error message, your code appears to be updating the database successfully. The issue lies with the use of fetchAll() after an update or insert query.
The error message "SQLSTATE[HY000]: General error" provides little information about the actual problem. It usually indicates a generic issue with the database query.
In your code, after executing the update query, you are using fetchAll() to retrieve the results. This method is typically used with select queries, where it retrieves all the rows returned by the query. However, for insert or update queries, fetchAll() is unnecessary and can cause errors.
To resolve the error, simply remove the fetchAll() statement:
<code class="php">try { $stmt = $pdo->prepare("UPDATE $page SET $section = :new_content WHERE $section = '$old_content'"); $stmt->execute(array( 'new_content' => $new_content )); echo "Database updated!"; } catch(PDOException $e) { echo 'ERROR UPDATING CONTENT: ' . $e->getMessage(); }</code>
The above is the detailed content of Why is fetchAll() causing a \'SQLSTATE[HY000]: General Error\' in PDO when updating a database?. For more information, please follow other related articles on the PHP Chinese website!