this is the code to insert json in my sql
function insert_ema($json){
$a= new Sql();
$b=$a->connection;
$sql = "INSERT INTO ema (ema_ten) VALUES ('$json')";
if ($b->query($sql) === TRUE) {
echo PHP_EOL." New record created successfully \n";
} else {
echo PHP_EOL." Error: " . $sql . "<br>" . $b->error;
}
$b->close();
;}
insert_ema('{"firstName":"John", "lastName":"Doe","3":"Jo", "4":"Do"}');
+----------------------------------------------------------------+----+
| ema_ten | id |
+----------------------------------------------------------------+----+
| {"3": "Jo", "4": "Do", "lastName": "Doe", "firstName": "John"} | 1 |
| {"3": "Jo", "4": "Do", "lastName": "Doe", "firstName": "John"} | 2 |
+----------------------------------------------------------------+----+
the sql saved above is in reverse order!! how can i fix it
The reason why I want to persevere order is, I want to be able to convert the json to an array and use pop .
I think MySQL should save arrays and also sort this issue.