LODatabase is a simple, file-based PHP database class that works with JSON and plain text files. It includes essential CRUD functions and supports transaction-like behavior using action queuing, commit, and rollback.
Refresh the webpage to see a new example.
<?php
require_once 'lodatabase.php';
// Demo file
$fname = 'demo-' . uniqid() . '.json';
// Create a new database
$db = new LODatabase($fname);
// Add user preferences
$db->insert(['theme' => 'dark', 'language' => 'en', 'notifications' => true]);
$db->insert(['theme' => 'light', 'language' => 'es', 'notifications' => false]);
$db->insert(['theme' => 'dark', 'language' => 'fr', 'notifications' => true]);
$db->commit();
// Find dark theme users
$darkThemeUsers = $db->select(function($row) {
return $row['theme'] === 'dark';
});
echo "<h3>Dark Theme Users:</h3>\n";
print_r($darkThemeUsers);
echo "\n";
// Update preferences
$db->update(['id' => 2, 'notifications' => true]);
$db->commit();
// Show all preferences
$preferences = $db->select();
echo "<h3>All Preferences:</h3>\n";
print_r($preferences);
echo "\n";
// Clean up
unlink($fname);<h3>Dark Theme Users:</h3> Array ( [0] => Array ( [id] => 3 [theme] => dark [language] => fr [notifications] => 1 ) [1] => Array ( [id] => 1 [theme] => dark [language] => en [notifications] => 1 ) ) <h3>All Preferences:</h3> Array ( [0] => Array ( [id] => 3 [theme] => dark [language] => fr [notifications] => 1 ) [1] => Array ( [id] => 2 [theme] => light [language] => es [notifications] => ) [2] => Array ( [id] => 1 [theme] => dark [language] => en [notifications] => 1 ) )