How does SQLite differ from MySQL in terms of functionality for creating and querying databases with PHP?
SQLite is a lightweight, serverless database engine that is often used for local storage in mobile apps or small-scale projects. MySQL is a more robust, client-server database management system that is commonly used for larger applications with multiple users. In terms of functionality for creating and querying databases with PHP, SQLite is simpler to set up and use, while MySQL offers more advanced features and scalability.
// Using SQLite with PHP
// Create a new SQLite database
$database = new SQLite3('database.db');
// Create a table
$database->exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
// Insert data
$database->exec("INSERT INTO users (name) VALUES ('John')");
// Query data
$results = $database->query('SELECT * FROM users');
while ($row = $results->fetchArray()) {
echo $row['name'] . "\n";
}
// Close the database connection
$database->close();