How do I connect to SQLite

Connecting to SQLite in PHP is a straightforward process. You'll need to use the SQLite3 class provided by PHP to open a database file and execute SQL commands. Here's a simple example of how to do this:

<?php // Create (or open) the database $db = new SQLite3('example.db'); // Create a table $db->exec("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)"); // Insert data into the table $db->exec("INSERT INTO users (name) VALUES ('John Doe')"); // Query the database $results = $db->query('SELECT * FROM users'); while ($row = $results->fetchArray()) { echo $row['name'] . '<br>'; } // Close the database connection $db->close(); ?>

SQLite PHP database SQLite3