0

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;
?>
2
  • 2
    You can't echo the result. I'd suggest reading the documentation, which gives plenty of examples to show what you need to do. Commented Oct 8, 2018 at 16:38
  • If you're just trying to see the result set for debug/visualization purposes, wrap the result, like this: print_r($result); Commented Oct 8, 2018 at 16:48

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.