PHP code example of joaojkuligowski / mypersist

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

    

joaojkuligowski / mypersist example snippets


use Joaojkuligowski\Mypersist\Base;

$persistBase = new Base('PDO', 'sqlite:base.db');

use Joaojkuligowski\Mypersist\Base;

$persistBase = new Base('JSON', 'file.json');

$data = [
    'name' => 'John Doe',
    'email' => '[email protected]',
];

$persistBase->insert('users', $data);

$users = $persistBase->select('users', ['email' => '[email protected]']);
print_r($users);

$data = [
    'email' => '[email protected]',
    'name' => 'Johnathan Doe', // Update name if email already exists
];

$persistBase->upsert('users', $data, 'email'); // 'email' is the unique key

$table1 = 'users' ;
$table2 = 'invoices' ;
$joinColumnTable1 = 'code' ;
$joinColumnTable2 = 'userCode' ;

$persistBase->join($table1, $table2, $joinColumnTable1, $joinColumnTable2);