Inserting BLOBs through PHP are always 0 bytes I'm making a site that allows users to upload small thumbnails for books they post. I want to store them as a BLOB.

The first row there was inserted manually through phpMyAdmin. The second row was uploaded through a PHP script. The two string values are evidently going through, but the blob I'm uploading isn't.

error_reporting(E_ALL);
ini_set("display_errors", 1);

include './getConnection.php';
include './getTokenData.php';

$conn = getConnection();

$image = addslashes(file_get_contents($_FILES['pic']['tmp_name']));
$name = $_POST['name'];
$desc = $_POST['desc'];


$SQL = "INSERT INTO  `db_bookclub`.`t_book` (
`c_name` ,
`c_description`,
`c_image`
)
VALUES (
?,?,?
);
";


echo $image;


$stmt = $conn-&gt;prepare($SQL);
$stmt-&gt;bind_param('ssb', $name, $desc, $image);
$stmt-&gt;execute();


When I echo $image, the image data (a whole bunch of characters) are sent to to the client, showing that the image is making it to the PHP script unmolested.

I have a feeling this is because of a settings file I haven't heard of. I've also tried mysql_real_escape_string in place of addslashes.
After a lot of searching, I found the keyword, send_long_data.

$stmt = $conn-&gt;prepare($SQL);
$stmt-&gt;bind_param('ssb', $name, $desc, $image);
$stmt-&gt;send_long_data(2, $image);

$stmt-&gt;execute();


A simple fix if you know the magic word.