dongwolu5275 2018-10-08 16:36
浏览 39
已采纳

无法从php和sqlite db获取表中的数据

I want to echo onto my screen all the data is my 'userdata' table. i have looked around and found this code but when i run it i get a HTTP ERROR 500. this is my code that im trying to use:

<?php
    $database = new SQLite3('home.db');

    $result = $database->query("SELECT * FROM userdata");
    echo $result;
?>
  • 写回答

1条回答 默认 最新

  • dongteng2534 2018-10-08 16:52
    关注

    the $database->query() method will return an SQLite3Result object which you can't just "echo". Instead, you should loop through all the results like so:

    <?php
        $database = new SQLite3('home.db');
    
        $result = $database->query("SELECT * FROM userdata");
    
        while ($row = $result->fetchArray()) {
            print_r($row);
        }
    ?>
    

    The $row variable inside the while loop will be an array. Use the appropriate index to get the value of a single column if necessary.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上