Wersja plikowej bazy danych Flinstone 2.0, MIT License, działa dla PHP 5.6+
Instalacja na localhost odbywa się po zainstalowaniu Composera:
composer require fire015/flintstone
Zawartość pliku composer.json powinna zawierać numer pobieranej wersji:
{ "require": { "fire015/flintstone": "2.*" } }
Uruchamiamy Flinstone w skrypcie:
<?php require 'vendor/autoload.php'; use FlintstoneFlintstone; $options = ['dir' => '/path/to/database/dir/']; $users = new Flintstone('users', $options);
Przykład:
// Set options $options = ['dir' => '/path/to/database/dir/']; // Load the databases $users = new Flintstone('users', $options); $settings = new Flintstone('settings', $options); // Set keys $users->set('bob', ['email' => 'bob@site.com', 'password' => '123456']); $users->set('joe', ['email' => 'joe@site.com', 'password' => 'test']); $settings->set('site_offline', 1); $settings->set('site_back', '3 days'); // Retrieve keys $user = $users->get('bob'); echo 'Bob, your email is ' . $user['email']; $offline = $settings->get('site_offline'); if ($offline == 1) { echo 'Sorry, the website is offline<br />'; echo 'We will be back in ' . $settings->get('site_back'); } // Retrieve all key names $keys = $users->getKeys(); // returns array('bob', 'joe', ...) foreach ($keys as $username) { $user = $users->get($username); echo $username.', your email is ' . $user['email']; echo $username.', your password is ' . $user['password']; } // Delete a key $users->delete('joe'); // Flush the database $users->flush();
Metody dostępu do danych:
get(string $key) Zwraca klucze tablicy. Wraca jako false jeśli nie znajduje danych klucza. set(string $key, mixed $data) Dodajemy nowe dane dla podanego klucza tablicy $key. Dane mogą być dostępne jako string, integer, float lub tablica array. Wyświetli wyjątek, jeśli format będzie nieprawidłowy. delete(string $key) Kasuje wskazaną przez podany klucz linię w pliku bazy tekstowej. Wyświetli wyjątek, jeśli nie znajdzie tych danych. flush() Czyści zawartość database. Wyświetli wyjątek, jeśli nie uda się wyczyścić plik poleceniem flush. getKeys() Zwróci klucze tablicy. getAll() Zwróci pełne dane z pliku bazy danych.
Cache-owanie
Jeśli potrzebujemy przyśpieszyć działanie przez uruchomienie własnego keszowania (np. Memcached), możemy wywołać klasę jako opcję. Należy mieć pewność, że to uruchomi: FlintstoneCacheCacheInterface
Dokumentacja: http://www.xeweb.net/flintstone/docs/Flintstone/Flintstone.html
- http://archive.is/7bzmU
- http://archive.is/5QbhR
Methods:
__construct(string $line)
string: getLine()
string: getKey()
string: getData()
- http://archive.is/mwLsX
- http://archive.is/KOHNg
- http://archive.is/rrlr4
- http://archive.is/HnZGP