在PHP / SQLite中获取图像路径 [英] Get Path of Image in PHP/SQLite

查看:68
本文介绍了在PHP / SQLite中获取图像路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在SQLite数据库中获取图像的路径。这是我的代码:

I am attempting to get the path of an image in an SQLite database. This is my code:

<img src="<?php
    $database = new PDO("sqlite:database.sqlite");
    $database->query("SELECT path FROM images WHERE receiverId = '$_COOKIE['session']'");
?>" />

表格是图片,用户的ID存储在Cookie中。

The table is images and the id of the user is stored in the cookie.

图像有3个条目: id senderId receiverId 。如果 receiverId 与cookie标识(用户标识)相同,则应显示图像。但是,此代码不起作用。如何修复/重新编码它?

An image has 3 entries: id, senderId and receiverId. If the receiverId is the same as the cookie id (the user id), the image should be displayed. However, this code is not working. How can I fix it/recode it?

推荐答案

您需要获取查询结果:

<?php

  $database = new PDO('sqlite:database.sqlite');
  $r = $database->query('SELECT path FROM images WHERE receiverId = ' . $database->quote($_COOKIE["session"]));
  $v = $r->fetch(PDO::FETCH_ASSOC);

?>
<img src='<?= $v["path"] ?>'>






为了使您的问题更容易找到,调试语句:


To make finding your problem easier, add a few debug statements:

// ... create $database
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// ... run the query (creating $r)
var_dump($r);

// ... fetch the results
var_dump($v);

这篇关于在PHP / SQLite中获取图像路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆