How does the choice between using JSON or a database like SQLite impact performance in terms of storing and retrieving notes?

Using a database like SQLite for storing and retrieving notes typically offers better performance compared to using JSON. This is because databases are optimized for handling large amounts of data efficiently, with features like indexing and query optimization. On the other hand, using JSON may be simpler for smaller datasets but can become slower as the amount of data grows.

// Example of storing and retrieving notes using SQLite database in PHP

// Connect to SQLite database
$db = new SQLite3('notes.db');

// Create table for notes if it doesn't exist
$db->exec('CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, title TEXT, content TEXT)');

// Insert a new note
$db->exec("INSERT INTO notes (title, content) VALUES ('Note Title', 'Note Content')");

// Retrieve all notes
$results = $db->query('SELECT * FROM notes');
while ($row = $results->fetchArray()) {
    echo $row['title'] . ': ' . $row['content'] . "\n";
}

// Close database connection
$db->close();