PHP code example of jameslevi / nest

1. Go to this page and download the library: Download jameslevi/nest 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/ */

    

jameslevi / nest example snippets




use Graphite\Component\Nest\Nest;

Nest::setStoragePath(__DIR__."/storage/cache");

Nest::setHashAlgorithm("md5");



use Graphite\Component\Nest\Nest;

// Set the default storage path.
Nest::setStoragePath(__DIR__."/storage/cache");

// Set the default hash algorithm.
Nest::setHashAlgorithm("md5");

// Create a new nest database instance.
$db = new Nest("db");

// Add data to cache.
$db->add("host", "localhost");
$db->add("port", 8080);
$db->add("username", "root");
$db->add("password", "123");
$db->add("database", "users");
$db->add("charset", "utf-8");

// Generate or update the cache file.
$db->write();

 return array (
  '67b3dba8bc6778101892eb77249db32e' => 'localhost',
  '901555fb06e346cb065ceb9808dcfc25' => '3306',
  '14c4b06b824ec593239362517f538b29' => 'root',
  '5f4dcc3b5aa765d61d8327deb882cf99' => '123',
  '11e0eed8d3696c0a632f822df385ab3c' => 'users',
  'dbd153490a1c3720a970a611afc4371c' => 'utf-8',
);

$db->get("host"); // Returns "localhost".

// Array will be automatically converted into json string.
$db->add("tables", array(
    "user_logs", 
    "user_contacts", 
    "user_address"
)); 

$db->set("password", "abc"); // Change the value of password from "123" to "abc".

$db->write();

$db->has("charset"); // Returns true because charset exists from our cache.

$db->remove("port"); // This will delete port from our cache.

$db->toArray();

$db->toJson();

Nest::db(); // Is equal to "new Nest('db')"

Nest::db('charset'); // Will return "utf-8".

Nest::db('username', 'james')->write(); // Will change the value of username from "root" to "james".

Nest::db()->add('token', '1jds9ds93209sdds')->write();

Nest::db()->remove('token')->write();

Nest::destroy('db');

Nest::destroyAll();