Lorenzo Lorenzo - 7 months ago 13
PHP Question

Database path on raspberry

I'm new in raspberry and I'm trying to read a simple database from a php page but there is something wrong: I can't read the database content: Here the php page code:

<!DOCTYPE html>
<html>
<body>
<H1>Test Database</H1>

<?php

$sq = sqlite_open('miodatabase.db', 0666, $sqlite_error);

if(!$sq)
{
die(“Errore Sqlite: “.$sqlite_error);
}

$result = sqlite_query($sq, 'select * from test');
while($data = sqlite_fetch_array($result))
{
echo $data[‘nome’];
}
sqlite_close($sq);
?>

</body>
</html>


The database is "miodatabase" that contains a table called "test". I put the database in \var\www\html folder (is correct?) but when I open the page I see a blank page. I'm sure the database contains the table (tested with sqlite3 commands) and the table contains one row. Where I need to put the database? Why I can't see nothing? Thanks

Answer

If you don't see anything, i think it's a php configuration issue.

Did you try to add :

  <?php  phpinfo(); ?>

at the beginning of your script. If you have blank page, look your apache/nginx configuration.

You can also try to run your script from the command line. Maybe helpful in some case.

UPdate

If you use SQLite3 follow this code

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

$db = new MyDB();
$result = $db->query('select * from test', SQLITE3_OPEN_READWRITE );

//var_dump($result->fetchArray());
while($data = $result->fetchArray())
{
   echo $data[‘nome’];
}
$db->close();