insertVideoData函数应将视频详细信息上传到我的数据库中。但是不知何故,数据库中什么也没有。我假设函数没有被正确调用...
我试图连接到另一个数据库,但是同样的问题。 连接确实起作用(我可以从数据库中获取信息)。 我的应用程序有权获取POST信息。 所有数据库字段均具有默认值,并且为文本或int格式。
// Step1: this is the processing code
$videoUploadData = new VideoUploadData(
$_FILES["fileInput"],
$_POST["titleInput"],
$_POST["descriptionInput"],
$_POST["privacyInput"],
$_POST["categoryInput"],
"REPLACE-THIS"
);
$videoProcessor = new VideoProcessor($con);
$wasSuccessful = $videoProcessor->upload($videoUploadData);
// Step2: this code creates the class VideoUploadData
class VideoUploadData {
public $videoDataArray, $title, $description, $privacy, $category, $uploadedBy;
public function __construct($videoDataArray, $title, $description, $privacy, $category, $uploadedBy) {
$this->videoDataArray = $videoDataArray;
$this->title = $title;
$this->description = $description;
$this->privacy = $privacy;
$this->category = $category;
$this->uploadedBy = $uploadedBy;
}
}
// Step 3: this code creates the database upload
class VideoProcessor {
private $con;
public function __construct($con) {
$this->con = $con;
}
public function upload($videoUploadData) {
$targetDir = "uploads/videos/";
$videoData = $videoUploadData->videoDataArray;
$tempFilePath = $targetDir . uniqid() . basename($videoData["name"]);
if(move_uploaded_file($videoData["tmp_name"], $tempFilePath)) {
$finalFilePath = $targetDir . uniqid() . ".mp4";
if(!$this->insertVideoData($videoUploadData, $finalFilePath)) {
echo "Insert query failed";
return false;
}
}
}
private function insertVideoData($uploadData, $filePath) {
$query = $this->con->prepare("INSERT INTO `videos` (`uploadedBy`, `title`, `description`, `privacy`, `filePath`, `category`)
VALUES (:uploadedBy, :title, :description, :privacy, :filePath, :category)");
$query->bindParam(":uploadedBy", $uploadData->uploadedBy);
$query->bindParam(":title", $uploadData->title);
$query->bindParam(":description", $uploadData->description);
$query->bindParam(":privacy", $uploadData->privacy);
$query->bindParam(":filePath", $filePath);
$query->bindParam(":category", $uploadData->category);
return $query->execute();
}
我希望该代码可以创建数据库条目,但是什么也没有发生(甚至没有错误代码)。