Testing SQLite HTML-Kit with PHP

SQLite is a lightweight database included with PHP 5.0 that we will use this quarter.

Using HTML-Kit's edit window, copy and paste the code below into the window and save it as "sqlite.php" in your <Server Root>\htdocs\ folder for testing purposes

<html>
<head>
 <title>sqlite</title>
</head>
<body>
<?php

//create or open database
$db = sqlite_open("test.db")
      or die("failure");

//create table
sqlite_query($db, 
  "CREATE TABLE Members(FirstName, Number)");

//add info
sqlite_query($db,
 "INSERT INTO Members VALUES ('Ed', 10)");
sqlite_query($db,
 "INSERT INTO Members VALUES ('Fred', 20)");
sqlite_query($db,
 "INSERT INTO Members VALUES ('Jim', 30)");

//get info
$dt = sqlite_query($db, "SELECT * FROM Members");
while ($row = sqlite_fetch_array($dt)) {
 echo "row: $row[FirstName] $row[Number]<br/>";
}
?>
</body>
</html>

In HTML-Kit, press F8 to preview the "sqlite.php" page in browser. The Web page should display:

row: Ed 10
row: Fred 20
row: Jim 30

Use My Computer to verify that the database file test.db was created in folder <Server Root>\htdocs\

Next: References