Из-за чего не получается спарсить данные из xml-файла?
<?php
function insert($name, $descriptions, $year, $rating, $poster, $category_id) {
$mysqli = new mysqli('localhost', 'root', '', 'kinomonster');
if(mysqli_connect_errno()) {
print_f('Соедение не установлено');
exit();
}
$mysqli->set_charset('utf8');
$query = "INSERT INTO movie VALUES(null, '$name', '$descriptions', '$year', '$desc', '$rating', '$poster', Now(), '$category_id')";
$result = false;
if($mysqli->query($query)) {
$result = true;
}
return $result;
}
function insert2($name, $descriptions, $year, $rating, $poster, $category_id) {
$mysqli = new mysqli('localhost', 'root', '', 'kinomonster');
if(mysqli_connect_errno()) {
print_f('Соедение не установлено');
exit();
}
$mysqli->set_charset('utf8');
$query = "INSERT INTO serials VALUES(null, '$name', '$descriptions', '$year', '$rating', '$poster', Now(), '$category_id')";
$result = false;
if($mysqli->query($query)) {
$result = true;
}
return $result;
}
//$xml = simplexml_load_file("xml_files/movies.xml") or die("Error: Cannot create object");
//echo count($xml);
/*
$title = null;
$title_orign = null;
$post = null;
$rating = null;
$year = null;
foreach ($xml as $movie_key => $movie) {
$title = $movie->title_russian;
$title_orign = $movie->title_original;
$year = $movie->year;
$desc = $movie->desc;
foreach ($movie->poster->big->attributes() as $poster_key => $poster) {
$post = $poster;
}
if($movie->imdb) {
$rating = $movie->imdb->attributes()['rating'];
} else {
$rating = null;
}
insert($title, $title_orign, $year, $desc, $rating, $post, 1);
}*/
$xml = simplexml_load_file("xml_files/serials.xml") or die("Error: cannot create object");
echo count($xml);
$title = null;
$title_orign = null;
$post = null;
$rating = null;
$year = null;
foreach ($xml as $movie_key => $movie) {
$title = $movie->title_russian;
$title_orign = $movie->title_original;
$year = $movie->year;
foreach ($movie->poster->big->attributes() as $poster_key => $poster) {
$post = $poster;
}
if($movie->imdb) {
$rating = $movie->imdb->attributes()['rating'];
} else {
$rating = null;
}
}
insert2($title, $title_orign, $year, $rating, $post, 2);
echo "<pre>";
print_r($xml);
echo "</pre>";
?>
**Почему-то в базу данных переносится полностью только один сериал. У меня есть всего два xml-файла, с фильмами(movies) и сериалами(serials), и их надо спарсить в таблицу mysql под названием movies. И это при том, что в xml-файле serials отсутствует поле desc. **