PHP Classes

File: example2.php

Recommend this page to a friend!
  Packages of Mihajlo Siljanoski   PHP JSON File Database   example2.php   Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: relations example
Class: PHP JSON File Database
Create and manipulate databases using JSON files
Author: By
Last change: Update of example2.php
Date: 4 years ago
Size: 652 bytes
 

 

Contents

Class file image Download
<?php
require_once 'lib/filedb.php';
$fdb=new filedb('anotherdatabase');




//example for adding in two tables (relation) at once posts and users

for($i=1;$i<=50;$i++){
    
    $fdb->insert('posts',[
        'title'=>'Example title '.$i,
        'description'=>'Example description will appear here '.$i,
        'author_id'=>$fdb->insert('users',['name'=>'Mihajlo_'.$i,'surname'=>'Siljanoski_'.$i],true)->_id
    ]);
    
}



//example of fetching results from 2 tables with relations at once (structured resultset)

$result=$fdb->get('posts',
        ['_id'=>15],
        ['author_id'=>['users','_id']]
        );

        print_r($result);