dp19001 2013-03-07 03:59
浏览 62
已采纳

在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?

  • 写回答

1条回答 默认 最新

  • dongluo9156 2013-03-07 04:18
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码