PDO Error - PDOException' with message 'SQLSTATE[HY000]: General error'

This is what happens:

  • You are trying to fetch an UPDATE query. You can't do that because UPDATE queries does not return values. If you wish to know how many rows were affected by the query, use the rowCount() function instead. Notice that not all DB Drivers provide the affected rows.

  • You are using undeclared variables (at least in the code you posted here). This isn't the reason for this particular error, but could generate others.

  • You're not using the data you have selected from the database

    Also, it is recommended to make all PDO operations within the try block, otherwise you may get unhandled exceptions.


For others who came here trying to decipher this esoteric error message as I did, let me add that:

Trying to run fetches on pdo statements like:

$statement->fetchAll();

or

$statement->fetchAll(PDO::FETCH_ASSOC);

...after an INSERT or UPDATE** statement can cause this error (since there is no data to fetch).

**The UPDATE ... RETURNING ... statement is an exception to this.

Tags:

Mysql

Php

Pdo