dongqian3198 2017-02-23 05:22
浏览 76
已采纳

“无法为非字符串/非二进制数据类型发送长数据”究竟是什么意思?

I am attempting to INSERT a single file's data into a LONGBLOB column via PHP along with some other data like the file's name, size in bytes, sha256 checksum, etc.

I know there is nothing wrong with the table itself, as I am able to INSERT the file and the rest of the columns all at once through phpMyAdmin which suggests that I use the following MySQL INSERT statement:

INSERT INTO DB_NAME.TABLE_NAME (SHA256SUM, FILE_NAME, FILE_DATA) VALUES (?, ?, ?)

So my PHP code currently looks like this:

$mysqli_query = 'INSERT INTO DB_NAME.TABLE_NAME (SHA256SUM, FILE_NAME, FILE_DATA) VALUES (?, ?, ?)';
$stmt = $mysqli->prepare($mysqli_query);
$null = NULL;
$stmt->bind_param("ssb", $sha256sum, $_FILES['career_application_FILE_UPLOAD']['name'], $null);
$stmt->send_long_data(0, file_get_contents($_FILES['career_application_FILE_UPLOAD']['tmp_name']));
$stmt->execute();

Which is pretty much exactly what Oracle suggests right here.

But for some reason it just hasn't been working for me. (And trust me, I have been trying for the past 3 hours.)

It kept returning the general MySQL error "COLUMN FILE_DATA CANNOT BE NULL".

So I enabled NULL values on the FILE_DATA column, and then the INSERT would work, but the FILE_DATA column (which is supposed to be filled with BLOB data) just reads NULL.

So I disabled NULL values on the FILE_DATA column and I placed a $stmt_error = $stmt->error; line just after the send_long_data section and I caught the following error:

Can't send long data for non-string/non-binary data types

I tried deciphering what that meant, and was unable to, so here I am asking for help.

I'm going to get some sleep, and hopefully in the morning I can answer my own silly question... I just have this feeling that it's something so entirely obvious I am too tired to notice it right now.

Some details:

  • I am running this code on Debian 8 and NGINX v1.6.2
  • I have quadruple-checked that my MySQL max_allowed_packet is set to the default 16776192 (which shouldn't matter anyways, as the files I am attempting to upload are a few bytes to a few kilobytes in size)
  • I have attempted uploading all different types of files (txt, mov, png, pdf, etc)
  • I am not unfamiliar with PHP or MySQL at all, I have been working with them both for over 10 years now
  • I even tried setting the LONGBLOB collation to binary, since the entire table's collation was ascii... but it wasn't possible to change the LONGBLOB collation, nor should it matter since like I said originally... phpMyAdmin has no problem inserting file data into the LONGBLOB column)

Thanks for reading.

  • 写回答

1条回答 默认 最新

  • dongwu9170 2017-03-02 00:06
    关注

    In my stupidity, I failed to read the spec for send_long_data in it's entirety and just assumed that 0 was an insignificant placeholder for something.

    It's not insignificant.

    It was meant to be 2. To equate to the 3rd parameter of the MySQL INSERT.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置