I am working on a system where I insert files into the database. There are two ways how I am able to insert blob into DB, so I'm curious which one is better.
The first is to get the content and then bind parameter of content as a string when inserting:
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
...
$prep_stmt = "INSERT INTO dokumenty (name, size, type, content, autor, poznamka) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $mysqli->prepare($prep_stmt);
$stmt->bind_param('sissis',$fileName,$fileSize,$fileType,$content,$user_id,$poznamka );
The other way is to use send_long_data like this:
$content = NULL;
...
$prep_stmt = "INSERT INTO dokumenty (name, size, type, content, autor, poznamka) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $mysqli->prepare($prep_stmt);
$stmt->bind_param('sisbis',$fileName,$fileSize,$fileType,$content,$user_id,$poznamka );
$stmt->send_long_data(3, file_get_contents($tmpName));
My question is: which way is better to use as both works?