在PHP / 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']'");
?>" />

The table is images and the id of the user is stored in the 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?

You need to fetch the results of the query:

<?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);