guvra / foundry
A simple yet powerful SQL query builder written in PHP.
1.0.2
2018-11-24 23:06 UTC
Requires
- php: >=7.2.0
Requires (Dev)
- phpunit/phpunit: ^7.2
- squizlabs/php_codesniffer: ^3.3
This package is auto-updated.
Last update: 2024-10-18 07:01:58 UTC
README
Description
Foundry is a simple yet powerful SQL query builder written in PHP.
Documentation
- Create a db connection
- Build a SELECT query
- Build an INSERT query
- Build a DELETE query
- Build an UPDATE query
- Execute the queries
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);