$host = 'localhost';
$db = 'kinomonster';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
try {
$mysqli = new mysqli($host, $user, $pass, $db);
$mysqli->set_charset($charset);
} catch (\mysqli_sql_exception $e) {
throw new \mysqli_sql_exception($e->getMessage(), $e->getCode());
}
unset($host, $db, $user, $pass, $charset); // we don't need them anymore
$stmt = $mysqli->prepare("INSERT INTO movie VALUES(null, ?,?,?,?,?, Now(),?)";
$stmt->bind_param("sssss", $name, $desc, $year, $rating, $poster, $category_id);
foreach ($xml as $movie_key => $movie) {
$title = $movie->title_russian;
$description = $movie->description;
$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;
}
$stmt->execute();
}