PHP code example of nozell / database

1. Go to this page and download the library: Download nozell/database library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nozell / database example snippets


    

    

use Nozell\Database\DatabaseFactory;

// Create a YAML database | Crear una base de datos en YAML
$db = DatabaseFactory::create('path/to/data.yml', 'yaml');

// Create a JSON database | Crear una base de datos en JSON
$db = DatabaseFactory::create('path/to/data.json', 'json');

// Create an SQLite database | Crear una base de datos en SQLite
$db = DatabaseFactory::create('path/to/data.db', 'sqlite');

$db->set("players", "Steve", ["kills" => 10, "deaths" => 2]);
$db->set("players", "Alex", ["kills" => 15, "deaths" => 3]);

$data = $db->get("players", "Steve");
if ($data !== null) {
    echo "Steve has " . $data["kills"] . " kills and " . $data["deaths"] . " deaths.";
}

$data = $db->get("jugadores", "Steve");
if ($data !== null) {
    echo "Steve tiene " . $data["kills"] . " kills y " . $data["deaths"] . " muertes.";
}

$db->delete("players", "Alex");

$db->delete("jugadores", "Alex");

$db->startTransaction();
$db->set("players", "Steve", ["kills" => 11]);
$db->set("players", "Alex", ["kills" => 17]);
$db->commitTransaction();  // Saves changes | Guarda los cambios
// $db->rollbackTransaction(); // Rollback changes | Deshacer los cambios

$db = DatabaseFactory::create('path/to/data.yml', 'yaml', false);

// Create an SQLite database | Crear una base de datos en SQLite
$db = DatabaseFactory::create('path/to/database.db', 'sqlite');