PHP code example of guvra / foundry

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

    

guvra / foundry example snippets


use Foundry\Connection;

$connection = new Connection(['dsn' => 'sqlite:db.sqlite']);

use Foundry\Parameter;

$select = $connection
    ->select()
    ->from(['t' => 'transactions'])
    ->join(['a' => 'accounts'], 'a.account_id = t.account_id')
    ->where('a.name', 'like', new Parameter('name'))
    ->orWhere('a.balance', 'between', [0, 1000])
    ->order('t.date desc');

$statement = $connection->query($select, [':name' => '%stock%']);
$rows = $statement->fetchAll();

$query = $connection
    ->insert()
    ->ignore()
    ->into('accounts')
    ->columns(['name', 'balance'])
    ->values([['Account 1', 0], ['Account 2', 450.59]]);

$connection->query($query);

$query = $connection
    ->update()
    ->table('accounts')
    ->values(['name' => 'Account 5'])
    ->where('name', '=', 'Account 1');

$connection->query($query);

$query = $connection
    ->delete()
    ->from('accounts')
    ->where('name', '=', 'Account 1');

$connection->query($query);