2017 © Pedro Peláez
 

library database

A database abstraction with support for various drivers.

image

vakata/database

A database abstraction with support for various drivers.

  • Monday, July 23, 2018
  • by vakata
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,143 Installations
  • PHP
  • 4 Dependents
  • 2 Suggesters
  • 0 Forks
  • 0 Open issues
  • 60 Versions
  • 7 % Grown

The README.md

database

Latest Version on Packagist ![Software License][ico-license] Build Status Scrutinizer Code Quality ![Code Coverage][ico-scrutinizer], (*1)

A database abstraction with support for various drivers (mySQL, postgre, oracle, ibase, sqlite and even PDO)., (*2)

Install

Via Composer, (*3)

``` bash $ composer require vakata/database, (*4)


## Usage ``` php $db = new \vakata\database\DB('mysql://user:pass@127.0.0.1/database_name?charset=utf8'); // get an array result: $db->all('SELECT id, name FROM table'); // [ [ 'id' => 1, 'name' => 'name 1' ], [ 'id' => 2, 'name' => 'name 2' ] ] // passing parameters $db->all('SELECT id, name FROM table WHERE id = ? OR id = ?', [ 1, 2]); // [ [ 'id' => 1, 'name' => 'name 1' ], [ 'id' => 2, 'name' => 'name 2' ] ] // if selecting a single column there is no wrapping array: $db->all('SELECT name FROM table'); // [ 'name 1', 'name 2' ] // setting a key for the resulting array $db->all('SELECT id, name FROM table', null, 'id'); // [ 1 => [ 'id' => 1, 'name' => 'name 1' ], 2 => [ 'id' => 2, 'name' => 'name 2' ] ] // skipping the key (which leaves a single column so it is not wrapped anymore) $db->all('SELECT id FROM table', null, 'id', true); // [ 1 => 'name 1', 2 => 'name 2' ] // selecting a single row: $db->one('SELECT id, name FROM table WHERE id = ?', [1]); // [ 'id' => 1, 'name' => 'name 1' ] // selecting a single value from a single row (no wrapping array): $db->one('SELECT name FROM table WHERE id = ?', [1]); // "name 1" // insert / update / delete queries (affected rows count and last insert ID) $db->query("UPDATE table SET name = ? WHERE id = ?", ['asdf', 1])->affected(); // 1 $db->query("INSERT INTO table (name) VALUES(?)", ['asdf'])->insertID(); // 3 $db->query("DELETE FROM table WHERE id = ?", [3])->affected(); // 1 // queries using the "all" method can also use the "get" method // "get" does not create an array in memory, instead it fetches data from the mysql client // the resulting object is not an array but can be iterated and supports indexes // basically it can be used as an array as it implements all neccessary interfaces foreach($db->get('SELECT id, name FROM table') as $v) { echo $v['id'] . ' '; } // 1 2 $db->get('SELECT id, name FROM table', null, 'id', true)[2]; // "name 2" // SHORTCUT METHODS // assuming there is a book table with a name column foreach ($schema->book() as $book) { echo $book['name'] . "\n"; } // you could of course filter and order foreach ($schema->book()->filter('year', 2016)->sort('name') as $book) { // iterate over the books from 2016 } // the same as above foreach ($schema->book()->filterByYear(2016)->sortByName() as $book) { // iterate over the books from 2016 } // if using mySQL or Oracle (others to come soon) foreign keys are automatically detected and can be fetched // for example if there is an author table and the book table references it foreach ($schema->book()->with('author') as $book) { echo $book['author']['name'] . "\n"; } // provided there is a linking table book_tag and a tag table and each book has many tags you can do this foreach ($schema->book()->with('tag') as $book) { echo $book['tag'][0]['name'] . "\n"; // the name of the first tag which the current book has } // filtering and ordering works on relations too $schema->book()->filter('author.name', 'A. Name'); // you can also specify what fields to select $schema->book()->select(['name', 'author.name']); // there are "low-level" where / order and limit methods $schema->book() ->with('author') ->where('created = CURDATE() OR promoted = ?', [1]) ->order("author.name ASC") ->limit(5) ->select(); // when not dealing with foreign keys you can also join tables (and use group by / having) $schema->categories() ->join('questions', [ 'category_id' => 'id' ]) ->group(['id']) ->having('cnt > ?', [300]) ->order('cnt DESC') ->limit(2) ->select(['id', 'cnt' => 'COUNT(questions.id)']) // you can also insert / update or delete records $schema->book()->insert(['name' => 'Book title']); $schema->book()->where('id = 5')->update(['name' => 'New title']); $schema->book()->where('id = 5')->delete();

Testing

bash $ composer test, (*5)

Contributing

Please see CONTRIBUTING for details., (*6)

Security

If you discover any security related issues, please email github@vakata.com instead of using the issue tracker., (*7)

Credits

License

The MIT License (MIT). Please see License File for more information., (*8)

The Versions

23/07 2018

dev-master

9999999-dev https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

23/07 2018

3.8.0

3.8.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

19/07 2018

3.7.5

3.7.5.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

02/07 2018

3.7.4

3.7.4.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

06/06 2018

3.7.3

3.7.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

31/05 2018

3.7.2

3.7.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

25/05 2018

3.7.1

3.7.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

25/05 2018

3.7.0

3.7.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

16/05 2018

3.6.2

3.6.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

08/05 2018

3.6.1

3.6.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

16/04 2018

3.6.0

3.6.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

11/04 2018

3.5.3

3.5.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

04/04 2018

3.5.2

3.5.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

13/12 2017

3.5.1

3.5.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

13/12 2017

3.5.0

3.5.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

13/12 2017

3.4.6

3.4.6.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

18/11 2017

3.4.5

3.4.5.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

10/11 2017

3.4.4

3.4.4.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

10/11 2017

3.4.3

3.4.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

02/11 2017

3.4.2

3.4.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

02/11 2017

3.4.1

3.4.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

01/11 2017

3.4.0

3.4.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

28/09 2017

3.3.0

3.3.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

14/09 2017

3.2.6

3.2.6.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

11/09 2017

3.2.4

3.2.4.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

11/09 2017

3.2.5

3.2.5.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

11/09 2017

3.2.3

3.2.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

31/07 2017

3.2.2

3.2.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

28/07 2017

3.2.1

3.2.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

23/06 2017

3.2.0

3.2.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

28/05 2017

3.1.1

3.1.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

13/05 2017

3.1.0

3.1.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

05/04 2017

3.0.3

3.0.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

05/04 2017

3.0.2

3.0.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

05/04 2017

3.0.1

3.0.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

05/04 2017

3.0.0

3.0.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

 

The Development Requires

database vakata

26/01 2017

2.0.1

2.0.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

24/01 2017

2.0.0

2.0.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

15/12 2016

1.4.0

1.4.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

08/12 2016

1.3.3

1.3.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

08/12 2016

1.3.2

1.3.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

02/12 2016

1.3.1

1.3.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

02/12 2016

1.3.0

1.3.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

30/11 2016

1.2.13

1.2.13.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

30/11 2016

1.2.12

1.2.12.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

30/11 2016

1.2.11

1.2.11.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

30/11 2016

1.2.10

1.2.10.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

30/11 2016

1.2.9

1.2.9.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

29/11 2016

1.2.8

1.2.8.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

28/11 2016

1.2.7

1.2.7.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

28/11 2016

1.2.6

1.2.6.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

19/11 2016

1.2.5

1.2.5.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

28/10 2016

1.2.4

1.2.4.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

27/10 2016

1.2.3

1.2.3.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

24/10 2016

1.2.2

1.2.2.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

12/09 2016

1.2.1

1.2.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

02/06 2016

1.2.0

1.2.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

12/05 2016

1.1.0

1.1.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

01/12 2015

1.0.1

1.0.1.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata

29/11 2015

1.0.0

1.0.0.0 https://github.com/vakata/database

A database abstraction with support for various drivers.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

database vakata