I have read several forums that advise against storing videos in a database. I unfortunately am forced to do so based on constraints for a school project I am working on. I was wondering if someone would let me know where I am going wrong when trying to store my video into the database. We are using an embedded procedure(someone else in my group wrote them that may be the problem)but after retrieving the video from the form it is returned as an Array which contains the name, type, error, location, etc(things associated with the video). After retrieving the array from the form I naively tried to insert the whole thing into the data based via function call through a query as seen below. This gives an immediate error "Unknown column 'Array' in 'field list' ". I get that Array is the type of $video
after we pull it from the form but I'm not sure where to go from there.
if(empty($_FILES['sonogram'])) {
echo 'The file exceeded maximum';
}
else {
$video = $_FILES['sonogram'];
}
//call our embedded procedure to add the video to the database
mysql_query("call SaveImage($studyId, $video, 'nothing new')");
Could anyone just let me know if I am making a simple error(syntax, etc..) or if there is something missing due to working with the blob/mp4.
Thanks
$_FILES is basically just an information array. It doesn't contain your actual file. You will need to open the file, read the content and then save it to the database.
Never tested the following, especially with videos:
// Read the video file content from the temp file.
// Usually on uploads you move the file.
$video = file_get_contents($_FILES['sonogram']['tmp_name']);
You have two entirely different and mostly unrelated tasks here: upload a file and pass it to your procedure.
The first one is explained in the Handling file uploads chapter of the PHP manual.
The second one depends on what SaveImage
expects: the file stream or a temporary file name. Since you are using the legacy mysql extension, which as far as I know does not provide specific support for BLOBs of binary columns, you'll have to inject the video into your SQL query with mysql_real_escape_string(). If your procedure expects the actual video contents, the query will probably exceed the maximum package size and will crash.