PHP Classes

File: src/Example/demo.php

Recommend this page to a friend!
  Classes of Joseluis Laso   Simple PHP Memory Database   src/Example/demo.php   Download  
File: src/Example/demo.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple PHP Memory Database
Manipulate databases stored in JSON format files
Author: By
Last change: fixing CS & MD
Date: 7 years ago
Size: 707 bytes
 

Contents

Class file image Download
<?php

namespace JLaso\SimpleMemoryDb\Example;

require_once
__DIR__.'/../../vendor/autoload.php';

use
JLaso\SimpleMemoryDb\RepositoryInterface;

/** @var RepositoryInterface[] $databases */
$databases = [];

$databases['customers'] = new CustomerTable(__DIR__.'/customers.json');
$databases['taxes'] = new TaxTable(__DIR__.'/taxes.json');

foreach (
$databases['customers']->findAll() as $customer) {
   
$tax = $databases['taxes']->find($customer['tax_type_id']);

   
printf(
       
"Customer (%d) %s applies %s [%f]\r\n",
       
$customer['id'],
       
$customer['name'],
       
$tax['name'],
       
$tax['percent']
    );
}

printf("There are %d customers\r\n", $databases['customers']->count());