[英]PDO Working With BLOBs (get image from table)
I have a little problem with getting an image from database table, maybe someone could help me. 我从数据库表中获取图像有一个小问题,也许有人可以帮助我。 I have an database named: 我有一个名为:
-RESPONSES with next rows->
id,
user_avatar,
first_name,
last_name,
msg_user,
user_date,
AND PHP insertion into DataBase: 和PHP插入数据库:
if (isset($_POST['r_sub'])) {
$image = $_FILES['r_image'];
$user_name = $_POST['r_username'];
$last_u_name = $_POST['r_lastname'];
$user_msg = $_POST['r_usermsg'];
$u_date = $_POST['r_date'];
$q_r = "INSERT INTO responses (user_avatar, first_name, last_name, msg_user, user_date) VALUES (:image, :user_name, :last_u_name, :user_msg, :u_date);";
$query_r = $pdo->prepare($q_r);
$results = $query_r->execute(array(
":image" => $image,
":user_name" => $user_name,
":last_u_name" => $last_u_name,
":user_msg" => $user_msg,
":u_date" => $u_date));
header("Location: index.php");
I'm wondering how to get a BLOB from table (in my case : user_avatar
); 我想知道如何从表中获取BLOB(在我的情况下: user_avatar
); maybe somebody has an a ready-made solution for this problem? 也许有人对此问题有现成的解决方案? I'm really need an example of code! 我真的需要一个代码示例!
try this 尝试这个
echo '<img src="data:image/jpeg;base64,'.base64_encode($image->load()) .'" />';
make sure that 确保
$image->load()
is your selected image from database 是您从数据库中选择的图像
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.