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.

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

报告相同问题?

悬赏问题

  • ¥65 LineageOs-21.0系统编译问题
  • ¥30 关于#c++#的问题,请各位专家解答!
  • ¥15 App的会员连续扣费
  • ¥15 不同数据类型的特征融合应该怎么做
  • ¥15 用proteus软件设计一个基于8086微处理器的简易温度计
  • ¥15 用联想小新14Pro
  • ¥15 multisim中关于74ls192n和DSWPK开关仿真图分析(减法计数器)
  • ¥15 w3wp,exe 中发生未处理的 Microsoft ,NETFramework 异常。
  • ¥20 C51单片机程序及仿真(加减器)
  • ¥15 AQWA | 水动力分析 二阶波浪力