BLOB是一種MySQL數據類型,稱為二進制大對象。正如它的名字它是用來存儲類似MYSQL二進制和VARBINARY類型的、大量的字符串數據。
MySQL BLOB分類
LONGBLOB ((2 ^ 32)1)
CREATE TABLE IF NOT EXISTS `output_images` ( `imageId` tinyint(3) NOT NULL AUTO_INCREMENT, `imageType` varchar(25) NOT NULL DEFAULT '', `imageData` mediumblob NOT NULL, PRIMARY KEY (`imageId`) )
0) { if(is_uploaded_file($_FILES['userImage']['tmp_name'])) { mysql_connect("localhost", "root", ""); mysql_select_db ("phppot_examples"); $imgData =addslashes(file_get_contents($_FILES['userImage']['tmp_name'])); $imageProperties = getimageSize($_FILES['userImage']['tmp_name']); $sql = "INSERT INTO output_images(imageType ,imageData) VALUES('{$imageProperties['mime']}', '{$imgData}')"; $current_id = mysql_query($sql) or die("Error: Problem on Image Insert
" . mysql_error()); if(isset($current_id)) { header("Location: listImages.php"); }}} ?>Upload Image to MySQL BLOB
Error: Problem on Retrieving Image BLOB
" . mysql_error()); $row = mysql_fetch_array($result); header("Content-type: " . $row["imageType"]); echo $row["imageData"]; } mysql_close($conn); ?>
" />
List BLOB Images " />