Skip to content

guvra/foundry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Foundry Query Builder

Description

Foundry is a simple yet powerful SQL query builder written in PHP.

Documentation

Usage Example

Initialization:

use Foundry\Connection;

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

Select:

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();

Insert:

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

$connection->query($query);

Update:

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

$connection->query($query);

Delete:

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

$connection->query($query);

About

PHP Query Builder

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages