10

I'm getting the error:

ERROR: SQLSTATE[HY000]: General error: 2053

I have no idea why this is happening because the code works fine and the database is updated, but it still returns this error.

Here's my code:

<?php header("Content-Type: application/json; charset=UTF-8"); require 'UHCauth.php'; try { $conn = new PDO("mysql:host=$mysql_serv;dbname=$mysql_db", $mysql_user, $mysql_pass); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); if(isset($_GET['d6518e47'])) { $USERNAME = $_GET['d6518e47']; $stmt = $conn->prepare( "UPDATE $mysql_table SET KILLS = KILLS+1 WHERE USERNAME = :USERNAME" ); $stmt->execute(array('USERNAME' => $USERNAME)); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode($row); } else { $stmt = $conn->prepare( "SELECT * FROM $mysql_table ORDER BY McVersion DESC, ModVersion DESC LIMIT 1" ); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); echo json_encode($row); } } catch(PDOException $e) { echo 'ERROR: ' . $e->getMessage(); } ?> 
3
  • 1
    Why are you trying to fetch results from an UPDATE query? Commented Mar 15, 2014 at 12:22
  • 1
    dev.mysql.com/doc/refman/5.0/en/… It's because of $stmt->fetch() after the UPDATE query, which does not return rows. Commented Mar 15, 2014 at 12:24
  • Actually, it's because I edited some previous code that I had and forgot to remove the bit that returns something in JSON format. Also, that just solved my problem. I removed the JSON code and now I'm not getting the error. Thanks! Commented Mar 15, 2014 at 12:26

1 Answer 1

18

$row = $stmt->fetch(PDO::FETCH_ASSOC); is the line that will cause your error.

Why?

Because there's nothing to fetch - in array - after an update

Remember that

PDO::FETCH_ASSOC: returns an array indexed by column name as returned in your result set

So, no result set ... no party

If you want to know exit status of your command, just use the return value of execute() function

$rv = $stmt->execute(array('USERNAME' => $USERNAME));

Sign up to request clarification or add additional context in comments.

1 Comment

Yep. I had copied this code from another project and forgot to remove that bit. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.