I can't figure this out. This is my variables:
$id = 1;
$exp = 1;
$energy = 1;
$payout = rand ( 100 , 300 );
here is the query
$sql = 'update players set ' .
'exp = exp + :exp, ' .
'energy = energy - :energy, ' .
'cash = cash + :cash ' .
'where id = :id';
An example of this as a string would be:
update players set exp = exp + 1, energy = energy - 1, cash = cash + 170 where id = '1'
When I input this in phpmyadmin
it works. Thats why I don't understand why this does not work:
try
{
$stmt = $this->db->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->bindParam(':exp', $exp, PDO::PARAM_INT);
$stmt->bindParam(':energy', $energy, PDO::PARAM_INT);
$stmt->bindParam(':cash', $payout, PDO::PARAM_INT);
$result = $stmt->execute();
$stmt->closeCursor();
}
catch (Exception $e)
{
die ($e->getMessage() );
}
if ( !$result )
{
trigger_error("mysql: " . $sql, E_USER_ERROR);
$data = array( "message" => T_gettext("Something went wrong."));
return json_encode( $data );
}
This results in a false $result
= something wrong with query.
What have I done wrong? + how do I get a more detailed mysql error message from PDO?