I receive on api an array from data
$array = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://shikimori.org/api/animes/31637'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, "User Agent"); if ($content = curl_exec($ch)) { $array = json_decode($content, true); } curl_close($ch); echo '<pre>'; print_r($array); Array
Array ( [id] => 31637 [name] => Gate: Jieitai Kanochi nite, Kaku Tatakaeri 2nd Season [russian] => Врата: Там бьются наши воины — Огнедышащие драконы [image] => Array ( [original] => /images/anime/original/31637.jpg?1453660380 [preview] => /images/anime/preview/31637.jpg?1453660380 [x96] => /images/anime/x96/31637.jpg?1453660380 [x48] => /images/anime/x48/31637.jpg?1453660380 ) [url] => /animes/31637-gate-jieitai-kanochi-nite-kaku-tatakaeri-2nd-season [kind] => tv [ongoing] => 1 [anons] => [status] => ongoing [episodes] => 12 [episodes_aired] => 4 [rating] => r [english] => Array ( ) [japanese] => Array ( [0] => GATE(ゲート)自衛隊 彼の地にて、斯く戦えり 第2クール) [synonyms] => Array ( [0] => Gate: Thus the JSDF Fought There! Fire Dragon Arc [1] => Gate: Jieitai Kanochi nite [2] => Kaku Tatakaeri - Enryuu-hen [3] => Gate Jieitai Kanochi Nite Kaku Tatakaeri 2nd Season ) [aired_on] => 2016-01-09 [released_on] => 2016-03-26 [duration] => 23 [score] => 8.17 [description] => Second season of the [i]Gate[/i] anime. Adapts Enryuu-hen, and Douran-hen arcs. [description_html] => Second season of the Gate anime. Adapts Enryuu-hen, and Douran-hen arcs. [favoured] => [thread_id] => 184926 [world_art_id] => 0 [myanimelist_id] => 31637 [ani_db_id] => 0 [rates_scores_stats] => Array ( [0] => Array ( [name] => 10 [value] => 231 ) [1] => Array ( [name] => 9 [value] => 99 ) [2] => Array ( [name] => 8 [value] => 84 ) [3] => Array ( [name] => 7 [value] => 35 ) [4] => Array ( [name] => 6 [value] => 15 ) [5] => Array ( [name] => 5 [value] => 3 ) [6] => Array ( [name] => 3 [value] => 1 ) [7] => Array ( [name] => 1 [value] => 1 ) ) [rates_statuses_stats] => Array ( [0] => Array ( [name] => Запланировано [value] => 2303 ) [1] => Array ( [name] => Смотрю [value] => 2023 ) [2] => Array ( [name] => Просмотрено [value] => 34 ) [3] => Array ( [name] => Отложено [value] => 52 ) [4] => Array ( [name] => Брошено [value] => 7 ) ) [genres] => Array ( [0] => Array ( [id] => 2 [name] => Adventure [russian] => Приключения [kind] => anime ) [1] => Array ( [id] => 1 [name] => Action [russian] => Экшен [kind] => anime ) [2] => Array ( [id] => 38 [name] => Military [russian] => Военное [kind] => anime ) [3] => Array ( [id] => 10 [name] => Fantasy [russian] => Фэнтези [kind] => anime ) ) [studios] => Array ( [0] => Array ( [id] => 56 [name] => A-1 Pictures Inc. [filtered_name] => A-1 Pictures Inc. [real] => 1 [image] => /images/studio/original/56.?1434707196 ) ) [videos] => Array ( [0] => Array ( [id] => 11435 [url] => http://youtu.be/oPfeTTcZGhs [image_url] => http://shikimori.org/images/31637 [player_url] => http://youtube.com/embed/oPfeTTcZGhs [name] => [kind] => PV [hosting] => youtube ) [1] => Array ( [id] => 12579 [url] => http://youtu.be/TrwXsOTWUeU [image_url] => http://shikimori.org/images/31637 [player_url] => http://youtube.com/embed/TrwXsOTWUeU [name] => [kind] => PV [hosting] => youtube ) ) [screenshots] => Array ( ) [user_rate] => ) How to parse it into variables for writing to the database? + there will even be a link or information where to dig in this direction
UPD: I tried to parse the array and add them to the database like this:
$name=($array["name"]); $russian=($array["russian"]); $kind=($array["kind"]); $status=($array["status"]); $episodes=($array["episodes"]); $episodes_aired=($array["episodes_aired"]);; $aired_on=($array["aired_on"]); $released_on=($array["released_on"]); $duration=($array["duration"]); $description=($array["description"]); $servername = "localhost"; $username = "root"; $password = ""; $dbname = "Animebase"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "INSERT INTO anime (name , russian , kind , status, episodes, episodes_aired, aired_on, released_on, duration, description ) VALUES('$name' , '$russian' , '$kind' , '$status', '$episodes', '$episodes_aired', '$aired_on', '$released_on', '$duration', '$description' )"or die("Ошибка…"); if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); As a result, everything seems to be inserted well, except for Russian words, instead of them, the interplay is inserted: UTF8_General_ci is selected in the table.
UPD2 added the line mysqli_set_charset ($ conn, "utf8"); Russian characters set off normally