easydb-io/easydb

A PHP client for easydb.io

dev-master 2019-11-25 05:43 UTC

This package is auto-updated.

Last update: 2024-04-25 16:01:47 UTC


README

This is the PHP client to connect with easydb.io databases.

Installation

Requires PHP 7.1

Install with composer:

composer require easydb-io/easydb

Usage

Instantiation

use EasyDB\EasyDB;

$config = require __DIR__ . '/config/databases.php';

$db = new EasyDB('db1', $config);

This assumes your environment variables are already loaded and you are not using this as a part of a framework.

For example, if you are using Laravel, you could just do this:

use EasyDB\EasyDB;

$db = new EasyDB('db1', config('easydb.db1'));

The config file has the ability to use multiple databases, and this instance I used the first one in the config file.

List

$db->list()

Returns all values stored.

Put

$db->put('test', 'hello world')

This operation will store scalar values as well as arrays. However please note that this operation already uses json_encode.

Get

$db->get($key)

Returns the value associated with the key. Please note this returns the raw json, so if you want an array you will have to call json_encode for yourself if you need to. For scalars you won't need to to this but if you stored an array and want to work on it server side, you will.

Delete

$db->delete($key)

Deletes the value associated with the key add returns and empty string.

Testing

If you want to run the tests, make sure you copy the .env.example to .env and fill it enter the credentials, or as mentioned above, inject the config variables in some other way.