<html>
<head>
<title>PHP Connection to SQLite Database</title>
</head>
<body>
<h1>PHP Connection to SQLite Database</h1>
<br>
<?php
$host = 'localhost';
$db = 'demo';
$user = 'demo';
$pswd = 'demo';
//Connect to SQLite database server -------------------------------------
$location = '/home/staff/sultan/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: SQLite $db database on: $host</b><br><br>");
//Perform select query -------------------------------------------------
$sql = 'select fname, lname, ssn from student'; #try 'select time()'
$result = $connect->query($sql);
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))
{
$fname = $row['fname'];
$lname = $row['lname'];
$ssn = $row['ssn'];
print("<tr> <td>$fname <td>$lname <td>$ssn ");
}
print('</table>');
//Release resources ----------------------------------------------------
$connect->close(); #close SQLite connection
?>
<?php include "zCode/include.php"; ?> <!-- hyperlink to see the code -->
</body>
</html>