1. Go to this page and download the library: Download habanero/grocery 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/ */
habanero / grocery example snippets
use Grocery\Base as DB;
# create a connection by DSN
$db = DB::connect('pgsql://postgres:test@localhost:5432/test#pdo');
# load existing table by accesing an array member
$foo = $db['my_table'];
# pick one row randomly!
$bar = $foo->select('*', [
'field' => 'value',
'OR' => [
'foo' => null,
'foo >=' => gmdate('Y-m-d H:i:s'),
], // WHERE "field" = 'value' AND ("foo" IS NULL OR "foo" >= '2023-08-22 23:45:12')
], [
'order_by' => [$db->rand()], // ORDER BY RAND|RANDOM()
]);
# create another table
$db['other_table'] = [
'id' => DB::pk(),
'title' => DB::str(['not_null' => true]),
'published_at' => DB::date(['default' => $db->now()]),
];
# inserting a new row
$db->other_table->insert([
'title' => 'Hello World!',
'published_at' => date('Y-m-d H:i:s'),
]);