I have written this small function which has two update two column. But it doesn't works how it should work. There's a column in the table named as currentstatus it's value has to be changed from Queued to Completed and a column usedtimes whose values needs to be incremented by +1. The increment doesn't happen as well.
I've been trying to fix this past couple of hours..but this doesn't seem to work.
What might be the issue? Any suggestions is appreciated.
function updateMessageQueue($indexid)
{
//this function would update that the messagequeue has been completed
$status = "Completed";
global $conn;
try
{
$statement = $conn->prepare("UPDATE messagequeue set currentstatus = :currentstatus AND usedtimes = usedtimes+1 where indexid = :index ");
$statement->bindParam(':currentstatus',$status);
$statement->bindParam(':index',$indexid);
$statement->execute();
$statement->closeCursor();
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
Use this
UPDATE messagequeue set currentstatus = :currentstatus , usedtimes = usedtimes+1
where indexid = :index
You've got an AND
keyword where a comma is expected.
The SQL syntax is invalid. As Bill Karwin points out, the SQL syntax is valid.
The AND
keyword causes this expression:
:currentstatus AND usedtimes = usedtimes+1
to be evaluated in boolean context, so the expression will return either a zero or NULL; and the result of that expression is assigned to the currentstatus
column.