Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO error: " SQLSTATE[HY000]: General error " When updating database

Tags:

php

pdo

I am getting an error when updating a database using PDO. I am new to PDO so maybe the problem is a small one and I just don't understand. Funny thing about the error, the command works fine and the database does actually get updated. But it still returns an error back at me.

Code:

try {     $stmt = $pdo->prepare("UPDATE $page SET $section = :new_content WHERE $section = '$old_content'");     $stmt->execute(array(         'new_content' => $new_content     ));     $result = $stmt->fetchAll();     echo "Database updated!"; } catch(PDOException $e) {     echo 'ERROR UPDATING CONTENT: ' . $e->getMessage(); } 

Error: ERROR UPDATING CONTENT: SQLSTATE[HY000]: General error

I literally have no idea where the problem could be because its very vaque and I haven't been able to find anyone with the same problem.

like image 833
loxyboi Avatar asked Oct 19 '12 17:10

loxyboi


1 Answers

You do not use fetchAll(),as in

$result = $stmt->fetchAll(); 

with update or insert queries. Removing this statement should rectify the problem.

like image 88
TranQ Avatar answered Sep 25 '22 08:09

TranQ