I'm trying to store a JSON-encoded array into MySql, but I get an error 1064.
My table structure:
And my code:
public static function addFriends($player, $friends = []){
$array = json_encode($friends);
$sql = "INSERT INTO friends (friends) VALUES ('$array') WHERE name = '" . $player . "'";
$query = DatabaseManager::getConnection()->query($sql);
if(!$query){
echo mysqli_errno(DatabaseManager::getConnection());
return;
}
echo 'Done';
}
The $friends
array is like ["Car", "Plane", "Bug"]
.