我有一个问题插入blob内容到表中并检索它,因为我的表由一些其他字段以及blob字段组成,数据插入正确,但当我试图获取图像时不显示。但相同的代码,如果我使用插入到一个单独的表只有2列的类型id,图像。检索是正确的。//插入I am using:
$图像= addslashes (file_get_contents(带有_file美元[' upload_file '] [' tmp_name ']));$image_type = $_FILES['upload_file']['type'];
INSERT INTO
questions
(id
,subject_id
,topic_id
,language
,question
,solution
,img_required
,image_type
,image
)值(12)"1","1","英语","QQQQ?"',"答"、"是的"、"图像/jpg ', ' BLOB-IMG001 ');
//在屏幕上显示图像,我使用:
$preview = $db->GetRow("SELECT * from questions where id='".mysql_real_escape_string($_REQUEST['id'])."
");预览('图像')= "美元;
但是如果我使用2个查询-插入和更新,其中插入语句将插入字段数据,然后用blob图像更新同一行。这工作得很好。我的问题是我不能让它插入完整的数据在一个单一的插入语句?这是我如何运行它目前-1) id =美元问题->插入(元数据);//
紧随其后2) $imgData =addslashes($_FILES['upload_file']['tmp_name']));imageProperties =带有_file美元[' upload_file ']['类型'];
$exe=$db->Execute("update pmd_questions set image_type='".$imageProperties.",形象= '"。imgData美元。"' where id='".$id.");
你可以做到。建议使用准备好的语句,并可以插入它。<>之前insertBlob($filePath, $mime) {$blob = fopen($filePath, 'rb');$sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)";$stmt = $this->pdo->prepare($sql);支撑-> bindParam(美元:mime, mime);$stmt->bindParam(':data', $blob, PDO::PARAM_LOB);返回$支撑-> execute ();}之前裁判:http://www.mysqltutorial.org/php-mysql-blob/