Unable to Display SQLIte query results in browser

Question

I am trying to display the results of a SQLite query on browser using php.

I connected to the database using

$conn = new PDO('sqlite:test.db');

Below is my query

$query = $conn->query("SELECT * FROM main");

Below is my fetch function

$row = $query->fetch(PDO::FETCH_ASSOC);

I get the output when I run it from my terminal using

php myscript.php

But when I try to open the same script from browser, its showing empty screen as it is not getting any response from server.

Can anybody help me debugging it ?

Please post if you have any working script for the same. I am out of due to submit my college project.


Show source
| pdo   | php   | sqlite   | sqlite3   2017-01-05 06:01 1 Answers

Answers ( 1 )

  1. 2017-01-05 06:01

    It's because of this:

    $conn = new PDO('sqlite:test.db');
    

    It's recommended that you choose an absolute file path with the directory being one that you know that the webserver user has read/write access to. For example if you are running under apache this will be a folder that the user apache (sometimes called httpd or nobody) can access.

    The other possibility is that your CLI version of PHP and the php plugin connected to the webserver are different. The latter has the sqlite extension installed while the former does not

◀ Go back