BLOB

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.

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.