What is the correct class name for handling SQLite databases in PHP?
To handle SQLite databases in PHP, you should use the SQLite3 class provided by PHP. This class allows you to create, read, update, and delete data in SQLite databases. You can use methods like query(), exec(), and prepare() to interact with the database.
// Create a new SQLite database connection
$db = new SQLite3('path/to/database.db');
// Example query to create a table
$query = "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)";
$db->exec($query);
// Example query to insert data into the table
$query = "INSERT INTO users (name, email) VALUES ('John Doe', 'john.doe@example.com')";
$db->exec($query);
// Example query to fetch data from the table
$results = $db->query("SELECT * FROM users");
while ($row = $results->fetchArray()) {
echo "ID: " . $row['id'] . ", Name: " . $row['name'] . ", Email: " . $row['email'] . "\n";
}
// Close the database connection
$db->close();
Keywords
Related Questions
- What are the best practices for designing PHP forms that require user confirmation before executing a specific action, such as deletion?
- What are the potential consequences of hosting PHP scripts on platforms like funpic.de that may not support them?
- How can error-handling be improved in PHP scripts, especially when dealing with database interactions?