1

I have an sqlite database with a config table with 3 rows: id, config and value.

I'd like to get the settings in this table in variables: how can I do that?

1 Answer 1

1

Here is a documentation how to use SQLite with PHP:

https://www.php.net/manual/en/book.sqlite.php

Edit: On the site you can see how it works

<?php
$dbhandle = sqlite_open('sqlitedb');
$query = sqlite_query($dbhandle, 'SELECT name, email FROM users LIMIT 25');
while ($entry = sqlite_fetch_array($query, SQLITE_ASSOC)) {
    echo 'Name: ' . $entry['name'] . '  E-mail: ' . $entry['email'];
}
?>
Sign up to request clarification or add additional context in comments.

6 Comments

Yeah, I already read that doc but $database['link'] = new SQLiteDatabase($database['uri']); $query = 'SELECT setting, value FROM config'; $result = $database['link']->arrayQuery($query); echo $result['name'] in example doesn't work. I don't know how to do that.
Do you get some errors? And what is you $database['uri']? Have you enabled you error reporting to get some errors?
$database['uri'] is where che sqlite database is located. When I try to print out $result['name'] I obtain... what? A few of minutes ago I obtained nothing. However, now I obtain turlandob, two values, but whithout any space. How can I divide and put them in variables?
With $query->fetch(SQLITE_ASSOC) in a while loop here is the documentation: de2.php.net/manual/en/function.sqlite-fetch-array.php
$query = 'SELECT setting, value FROM config'; //$result = $database['link']->arrayQuery($query); $result = $database['link']->unbufferedQuery($query); while ( $row = $result->fetch(SQLITE_ASSOC) ) { echo $row['name']; } I obtain Fatal error: Call to a member function fetch() on a non-object in /membri/turlando/site/includes/init.php on line 18. Line 18 is while ( $row = $result->fetch(SQLITE_ASSOC) ) {
|

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.