BLOB
- BLOB is the short-term used for Binary Large OBject. Example for Binary Large OBject is JPEG image.
- We can insert the these BLOB type using the mysql query. The effient method for blob data is using mysqli_stmt_send_long_data() function.
Example:
$conn = mysqli_connect(”localhost”, “user”, “”, “db”);
$stmt = $conn->prepare(”INSERT INTO files VALUES(NULL, ?)”);
$stmt->bind_param(”s”, $data);
$file = “img.jpg”;
$fp = fopen($file, “r”);
$size = 0;
while ($data = fread($fp, 1024)) {
$size += strlen($data);
$stmt->send_long_data(0, $data);
}
stmt->execute();
In the above example, we have inserted img.jpg into the table.And bind_param function is used to bind variables to a prepared statement. And send_long_data function is used to send block of datas.
