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.

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

报告相同问题?

悬赏问题

  • ¥20 vb6.0截取当前窗体保存为jpg文件
  • ¥20 苹果手机不使用大疆sdk怎么获取遥控器控制信息或如何接入大疆sdk并且成功上架sdk
  • ¥15 改动头文件造成的编译错误如何解决
  • ¥20 woocommerce 注册按键重定向
  • ¥100 求书法图像文字切割代码
  • ¥15 同一个波形探测距离不同的目标,为什么fft之后得到的频谱图会发生移动,不应该时移不改变幅度谱吗(标签-matlab)(相关搜索:matlab仿真)
  • ¥15 Proteus仿真程序只能执行一次
  • ¥15 语音识别websocket报错
  • ¥15 激光器,引脚问题,无法处理
  • ¥20 求写一份!只提交Mapper映射文件 如:UsersMapper.xml