3

I am trying to query a sqlite and I cant seem to figure out why my query returns nothing...Please let me know what I am doing incorrectly: Here is my code:

<?php

class MyDB extends SQLite3
{
    function __construct()
    {
        $this->open('zap.db');
    }
}

$dbname = new MyDB();
$tablename = "test";   

error_reporting (E_ALL ^ E_NOTICE); 

$result = "select user FROM test";
echo "here";

$row = $dbname->query($result);

foreach ($dbname->query("$result") as $row) {
        print $row["user"] . "\n";
    }

?>

1

2 Answers 2

6

SQLite3::query returns a result resource object. You need to use the fetchArray method on it to get rows from it:

$query = "select user FROM test";
echo "here";

$result = $dbname->query($query);

while ($row = $result->fetchArray()) {
    print $row["user"] . "\n";
}
Sign up to request clarification or add additional context in comments.

2 Comments

This doesn't use PDO :(
Neither does the question, see my comment on the question.
0
    class MyDB extends SQLite3
    {
        function __construct($db_name)
        {
            $this->open($db_name.".db");
        }

    }

$db = new MyDB($user_db);

$result = $db->query("your query ");

its working great with me in php... you must be enable SQLite3 module version and SQLite Library in your phpinfo file...

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.