使用php导入mysql blob数据

时间:2014-04-14 12:45:49

标签: mysql blob

我正在尝试使用blob格式在mysql中保存图像数据 这些是使用PHP正确插入和检索 我有一个问题,我需要为某些数据创建一个单独的sql文件,其中包括blob数据,当我尝试导入sql文件时,它无法导入blob数据

include 'database.inc.php';
if (isset($_FILES['sqlfile']) && !empty($_FILES['sqlfile'])) {
$filename=$_FILES['sqlfile']['name'];
$tmp_filename=$_FILES['sqlfile']['tmp_name'];
move_uploaded_file($tmp_filename, $filename);
$file_content=file_get_contents($filename);
$commands = explode(';',trim($file_content));
foreach ($commands as $command) {
    if(mysql_query($command)){
        //header('Location: '.$_SERVER['HTTP_REFERER']);
    } else {
        //echo 'Failed to import with following command <br/>'.$command;
        echo mysql_error();
    }
}
}

1 个答案:

答案 0 :(得分:1)

您必须正确编码SQL文件中的数据,例如this回答"How to insert BLOB and CLOB files in MySQL?"