簡體   English   中英

在LONGBLOB中存儲大(2MB)音頻文件時,Mysql服務器已經消失

[英]Mysql server has gone away while storing large (2MB) audio file in LONGBLOB

我想在mysql數據庫中存儲一個音頻文件。 我正在使用LONGBLOB來存儲此音頻文件的base64編碼字符串。 但正如我執行我的查詢,我收到此警告,沒有插入數據庫:

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

當我上傳任何圖像文件時,我沒有得到任何錯誤,代碼工作正常。 當我上傳視頻和音頻文件時會發生這種情況。 在我正在使用的代碼中:

<?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>

這是我正在調用的函數代碼:

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

注意:為什么要將音頻文件存儲在數據庫中,而是存儲它的路徑並將文件存儲在系統中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM