」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何在 PHP 中顯示 MySQL BLOB 映像?

如何在 PHP 中顯示 MySQL BLOB 映像?

發佈於2024-12-21
瀏覽:857

How to Display MySQL BLOB Images in PHP?

從MySQL 顯示PHP BLOB 影像

背景

在MySQL 資料庫中將影像作為二進位大物件(BLOB) 儲存和擷取是一種常見技術。然而,顯示這些圖像有時可能具有挑戰性。

解決方案

解決方案

  1. 插入映像:
使用file_get_contents 函數讀取映像
$query = "INSERT INTO products (image) VALUES(?)";
$stmt = $db->prepare($query);
$stmt->bind_param('s', $image);
$stmt->execute();
使用PREPARED STATEMENT 將映像資料插入到變數的BLOB 欄位中資料庫:

$query = "插入產品(影像)值(?)"; $stmt = $db->準備($query); $stmt->bind_param('s', $image); $stmt->execute();

  1. 顯示映像:
$query = "INSERT INTO products (image) VALUES(?)";
$stmt = $db->prepare($query);
$stmt->bind_param('s', $image);
$stmt->execute();
使用PREPARED STATMENT 從資料庫擷取影像資料:
  1. $query = "從產品中選擇*,其中id = ?"; $stmt = $db->準備($query); $stmt->bind_param('s', $id); $stmt->execute(); $result = $stmt->get_result(); $row = $result->fetch_array();
$query = "INSERT INTO products (image) VALUES(?)";
$stmt = $db->prepare($query);
$stmt->bind_param('s', $image);
$stmt->execute();
使用base64_encode對圖像資料進行編碼並將其顯示為如何在 PHP 中顯示 MySQL BLOB 映像? 標籤:

How to Display MySQL BLOB Images in PHP?

echo '如何在 PHP 中顯示 MySQL BLOB 映像?';

最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3