SERVER[''DOCUMENT_ROOT'']."/../library.db"; // open database file $handle = sqlite_open($db) or die("Could not open database"); // generate query string // this query returns only a single record with a single field $query = "SELECT author FROM books WHERE title = ''A Study In Scarlet''"; // execute query $result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle))); // if a row exists if (sqlite_num_rows($result) > 0) { // get the value of the first field of the first row echo sqlite_fetch_single($result); } // all done // close database file sqlite_close($handle); ?> </body> </html>
SERVER[''DOCUMENT_ROOT'']."/../library.db"; // open database file $handle = sqlite_open($db) or die("Could not open database"); // generate query string $query = "SELECT DISTINCT author FROM books"; // execute query $result = sqlite_query($handle, $query) or die("Error in query: ".sqlite_error_string(sqlite_last_error($handle))); // if rows exist if (sqlite_num_rows($result) > 0) { echo "<table cellpadding=10 border=1>"; // check for more rows while (sqlite_has_more($result)) { // get first field from each row // print values $row = sqlite_fetch_single($result); echo "<tr>"; echo "<td>".$row."</td>"; echo "</tr>"; } echo "</table>"; } // all done // close database file sqlite_close($handle); ?> </body> </html>
SERVER[''DOCUMENT_ROOT'']."/../library.db"; // create database object $db = new SQLiteDatabase($file) or die("Could not open database"); // generate query string $query = "SELECT DISTINCT author FROM books"; // execute query $result = $db->query($query) or die("Error in query"); // if rows exist if ($result->numRows() > 0) { echo "<table cellpadding=10 border=1>"; // check for more rows while ($result->valid()) { // get first field from each row // print values $row = $result->fetchSingle(); echo "<tr>"; echo "<td>".$row."</td>"; echo "</tr>"; } echo "</table>"; } // all done // destroy database object unset($db); ?> </body> </html>