Mysql
 sql >> Datenbank >  >> RDS >> Mysql

PHP-Anzeigebild BLOB von MySQL

Versuchen Sie es so.

Zum Einfügen in DB

$db = new mysqli("localhost", "root", "", "DbName");
$image = file_get_contents($_FILES['images']['tmp_name']);
$query = "INSERT INTO products (image) VALUES(?)";
$stmt = $db->prepare($query);
$stmt->bind_param('s', $image);
$stmt->execute();

Für den Zugriff auf das Bild von Blob

$db = new mysqli("localhost", "root", "", "DbName");
$sql = "SELECT * FROM products WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param('s', $id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array();
echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image']).'"/>';