I have an sql update query like this; please note that I just have a string of the query like $query:
$query = 'UPDATE "public"."activity" SET "itemid" = 2, "itemname" = 'sssd' WHERE "id" = 19';
From this stringified query, I can get the set clause separately as:
$setClause = '"itemid" = 2, "itemname" = 'sssd'';
I need to convert this set clause to a json array to send in an ajax request like:
{
"itemid": 2,
"itemname": "sssd"
}
So far I havent been able to figure this out; I looked online for a solution as well but couldn't find one. Any ideas please?
This did the job for me. Thanks to John Halbert for pointing it out in the comments.
public function GetJsonFromUpdateSetClause($setClause){
$sc2JSON1 = '{' . str_replace('=', ':', $setClause) . '}';
$sc2JSON2 = str_replace('\'', '\"', $sc2JSON1) ;
$sc2JSON3 = stripcslashes($sc2JSON2);
return $sc2JSON3;
}