MySQL服务器已经消失,而存储LONGBLOB大(2MB)音频文件 [英] Mysql server has gone away while storing large (2MB) audio file in LONGBLOB

查看:264
本文介绍了MySQL服务器已经消失,而存储LONGBLOB大(2MB)音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要存储在的mysql 数据库中的音频文件。我使用 LONGBLOB 存储的base64 连接此音频文件的codeD字符串。但正如我执行我的查询,我得到与数据库中没有插入这样的警告:

I want to store a audio file in mysql database. I am using LONGBLOB to store the base64 encoded string of this audio file. but just as i perform my query, i am getting this warning with no inserting on the database:

Warning: mysql_query() [function.mysql-query]: MySQL server has gone away 

当我上传任何图片文件,我得到任何错误和code正常工作。发生这种情况时,我上传的视频和音频文件。下面在code,我使用:

When i upload any image file, i am getting no error and the code works fine. this happens when i upload video and audio file. below in the code i am using:

<?php
    include 'database_handler.php';
    if(isset($_FILES['fileToUpload']['name'])){
    echo "uploading. . .";
    $file = rand(0, 10000000).$_FILES['fileToUpload']['name'];
    if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $file)) {
        if($fp = fopen($file,"rb", 0))
        {
           $picture = fread($fp,filesize($file));
           fclose($fp);
           $base64 = base64_encode($picture);
           //echo $base64;
           $db = new Database();
           $db->test($base64);
        }
    }
}
?>
<form action="test.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

下面是函数code那我打电话:

function test($base64String){
    if (mysql_query("update users set attribute1='$base64String' where id = '83'")){
                    echo "success";

                }else{
                    mysql_error();
                }
}

感谢

推荐答案

请增加 /etc/mysql/my.cnf,

wait_timeout = 3600

max_allowed_packet = 128M

和重新启动

sudo /etc/init.d/mysql restart

注意:你为什么要存储在数据库中的音频文件,而不是保存它的路径和文件存储在系统

Note: Why are you storing the audio file in the DB, instead store the path of it and store the file in system

这篇关于MySQL服务器已经消失,而存储LONGBLOB大(2MB)音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆