2011-11-29 18:51
浏览 86


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.


图片转代码服务由CSDN问答提供 功能建议

我读过几个建议不要在数据库中存储视频的论坛。 不幸的是,基于我正在研究的学校项目的限制,我被迫这样做。 我想知道在尝试将我的视频存储到数据库时是否有人会告诉我出错的地方。 我们正在使用嵌入式过程(我的小组中的其他人写了它们可能是问题)但是从表单中检索视频后,它将作为包含名称,类型,错误,位置等的数组返回(与之相关的事物) 该视频)。 从表单中检索数组后,我天真地试图通过函数调用通过查询将整个事物插入到数据中,如下所示。 这会在“字段列表”中立即显示错误“未知列'数组'”。 我从表单中提取后,得到的数组是 $ video 的类型,但我不确定从那里开始。

   if(空($ _ FILES ['sonogram'])){
else {
 $ video = $ _FILES ['sonogram']; 
mysql_query(“调用SaveImage($ studyId,$ video,'nothing new')”); 

任何人都可以让我知道我是否正在制作一个简单的错误(语法等)或者由于使用blob / mp4而丢失了一些东西。


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyujun0152 2011-11-29 18:55

    $_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']);
    点赞 打赏 评论
  • dongshangan2074 2011-11-29 19:45

    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.

    点赞 打赏 评论

相关推荐 更多相似问题