1

I have a very simple UPDATE command that I am attempting to execute but keep receiving a HTTP 500 internal server error.

$test = $mysqli->prepare('UPDATE `tname` SET column = ? WHERE `ID` = ?');
$test->bind_param('ii', $value, $id);
$test->execute();

I have been searching for the solution for the past few days to no avail.

The $mysqli object has been created and is NOT closed until after the above code is executed. This is confirmed by the fact that if I change the prepare statement to 'SELECT' or anything else besides 'UPDATE', it works successfully.

$value and $id are not null; if I echo them, the values are correct.

Strangely, this worked fine in my local environment and on Hostmonster before migrating to AWS. Might there be some setting I need to change? I wasn't able to find anything, and the problem seems to only be with calls that involve UPDATE.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Stone
  • 121
  • 5
  • 14
  • What does `echo $mysqli->error();` output? – Paul May 28 '12 at 23:38
  • Nothing is echoed; I just receive the HTTP 500 internal server error. And just to clarify, I tried a combination of 'or die($mysqli->error), echo $test->error(), etc'. All still result in an internal server error, and the server logs don't offer any helpful information. – Stone May 28 '12 at 23:50
  • Seems like php error.. Have you tried turning on error reporting ? Some variable might not be initialized @ the beginning.. – J A May 28 '12 at 23:50
  • @Stone Make sure you `exit;` or `die;` after this to stop any code that relies on a successful query execution from running. Also check your server and database error log. – Paul May 28 '12 at 23:52
  • So, if I use `or die($mysqli->error())` I get the internal server error. However, if I use something like `or die('prepare failed');`, prepare failed is echoed. Does this indicate that I've lost my connection to $mysqli? I see no reason for that to happen though. As I said before, if I use SELECT instead of UPDATE, it works fine. – Stone May 29 '12 at 00:17
  • I forgot to restart the php server after turning on display_errors. Now I'm getting the error `UPDATE command denied to user`. Any ideas? – Stone May 29 '12 at 01:22

1 Answers1

1

I've found the solution for my own question, so in case anyone encounters a similar issue, here's what I did:

  1. If you're getting HTTP 500 internal server errors, but you're positive the server configuration is correct, then you most likely have a PHP error, so go to php.ini and make sure error_reporting is E_ALL and display_errors is on. (You'll want to turn this off in a production environment.)

  2. With PHP errors turned on, the source of the problem should be obvious. For me, my DB user didn't have the UPDATE privilege (I didn't set up the DB, so I wasn't aware of this), so I just needed to GRANT the UPDATE privilege.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Stone
  • 121
  • 5
  • 14