<html>
<head>
<title>Test PHP Database Connection to SQLite</title>
</head>
<body>
<h1>Test PHP Database Connection to SQLite</h1>
<br><br>
<?php

    $host = 'localhost';
    $db   = 'demo';
    $user = 'demo';
    $pswd = 'demo';    

    // Connect to MySql database server -------------------------------------

    $location = '/home/sultans/data/sqlite/' .$db. '.db';       #location of SQLite database file
    if (! file_exists($location)) 
    {
        die('Could not connect: Database does not exist');
    }
 
    $connect = new SQLite3($location); 
    if (! $connect) {
        die('Could not connect: ' . $connect->lastErrorMsg());
    }

    print("<b>Connected to: $db SQLite database on: $host</b><br>");


    // perform select query -------------------------------------------------

    $result = $connect->query('select fname, lname, ssn from student');
    if (! $result) {
        die('Could not execute query: ' . $connect->lastErrorMsg());
    }
    print('<table border=1>');
    print('<tr bgcolor=gray><th>FNAME<th>LNAME<th>SSN');
    while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
        print("<tr><td>".$row['fname']."<td>".$row['lname']."<td>".$row['ssn']);
    }
    print('</table>');

    // release resources ----------------------------------------------------

    $connect->close();                                            #close SQLite connection 

 ?>

</body>
</html>