I am working on a system in which I insert files into a database. There are two ways I can insert blob into DB, so I'm curious which one is better.
First, to get the content, and then bind the content parameter as a string when pasting:
$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 );
Another way is to use send_long_data as follows:
$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, since both work?