我正在构建一个简单的“小”电影编目数据库系统供我自己使用。现在的问题是我有一个 mySQL 查询在大多数情况下都有效,但不是全部。基本上它通过使用第 3 方 IMDB API 来工作。我用它来搜索和提取我需要的值,效果很好。它显示在我的预览屏幕和所有内容上。我遇到的问题是,虽然大多数电影都有效,但有些电影却没有,我无法弄清楚原因。
例如,The Fellowship of the Ring 存储得很好,而 The Return of the King 根本不会通过查询。我找不到任何差异。
这是我的查询:
$query = "INSERT INTO movies
(title, year, releaseDate, actors, image, runtime, genre, director, rating, watchedDate, category, series, comments, owned, ownedFormat, seen, plot, favorite, uploadDate)
VALUES ('$title', '$year', '$releaseDate', '$actors', '$newImg', '$runtime', '$genre', '$director', '$rating', '$watchedDate', '$category', '$series', '$comments', '$owned', '$ownedFormat', '$seen', '$plot', '$favorite', '$curDate')";
mysql_query($query) or die ('Error');
我不确定我还需要提供什么。似乎电影中的某种差异导致了错误,但我不知道。
谢谢!
** 编辑 ** *
所以我尝试切换到mysqli。这是我的新代码:
/* Create the prepared statement */
if ($stmt = $mysqli->prepare("INSERT INTO movies (title, year, releaseDate, actors, image, runtime, genre, director, rating, watchedDate, category, series, comments, owned, ownedFormat, seen, plot, favorite, uploadDate) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) {
/* Bind our params */
$stmt->bind_param('sssssssssssssssssis', $title, $year, $releaseDate, $actors, $newImg, $runtime, $genre, $director, $rating, $watchedDate, $category, $series, $comments, $owned, $ownedFormat, $seen, $plot, $favorite, $curDate);
/* Execute the prepared Statement */
$stmt->execute();
/* Echo results */
echo "Inserted {$title} into database\n";
}
但是,现在我收到一条错误消息:致命错误:在 if 语句开始的行上的非对象上调用成员函数 prepare()。
我假设这是因为我的查询不是对象?
谢谢