2017 © Pedro Peláez
 

library database

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

image

thephpleague/database

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  • Tuesday, December 12, 2017
  • by SergeyPodgornyy
  • Repository
  • 1 Watchers
  • 2 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Database

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

PHP library and ORM to handle DB connection, apply C.R.U.D. operations., (*2)

Install

Via Composer, (*3)

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


## Usage ``` php $config = [ 'host' => 'localhost', 'port' => 3306, 'database' => 'master_db', 'username' => 'root', 'password' => '', ]; $connection = new League\Database\ConnectionManager('core', $config);

BulkSql usage

Bulk SQL classes could be useful in scripts, when you need to insert big amount of records., (*5)

Example 1:, (*6)

BulkInsert usage
, (*7)

``` php use League\Database\BulkSql\BulkInsert;, (*8)

$db = $connection->getMasterConnection();, (*9)

$bulkInsert = new BulkInsert($db, 'users'); $bulkInsert ->setItemsPerQuery(50) ->useIgnore() ->disableIndexes();, (*10)

try { $db->beginTransaction();, (*11)

foreach ($users as $user) {
    $bulkInsert->add($user);
}

$bulkInsert->finish();
$affectedCount = $bulkInsert->getAffectedCount();

$db->commit();

} catch (\PDOException $e) { $db->rollBack(); }, (*12)

</details>

**Example 2:**

<details>
    <summary>`BulkReplace` and `BulkDelete` usage (could be useful with feeds)</summary>

``` php
use League\Database\BulkSql\BulkReplace;
use League\Database\BulkSql\BulkDelete;

$db = $connection->getMasterConnection();

$bulkReplace = new BulkReplace($db, 'offers');
$bulkReplace->setItemsPerQuery(500);
$bulkDelete = new BulkDelete($db, 'offers');
$bulkDelete->setItemsPerQuery(1000);

try {
    $db->beginTransaction();

    foreach ($offers as $offer) {
        $flag = $offer['deltaStatus'] ?? null;

        switch ($delta) {
            case 'REMOVE':
                $bulkDelete->add(['id' => $data['id']]);
                break;
            case 'ADD':
                $bulkReplace->add($data);
                break;
            default:
                $logger->notice("Unsupported delta flag \"{$flag}\"";
        }
    }

    $bulkReplace->finish();
    $bulkDelete->finish();

    $db->commit();

    $insertsCount = $bulkReplace->getInsertedCount();
    $updatesCount = $bulkReplace->getReplacedCount();
    $deletesCount = $bulkDelete->getAffectedCount();
} catch (\PDOException $e) {
    $db->rollBack();
}

, (*13)

Change log

Please see CHANGELOG for more information on what has changed recently., (*14)

Testing

bash $ composer test, (*15)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*16)

Security

If you discover any security related issues, please email sergey.podgornyy@yahoo.de instead of using the issue tracker., (*17)

Credits

License

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

The Versions

12/12 2017

dev-master

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

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  Sources   Download

MIT

The Requires

 

The Development Requires

database postgres mysql thephpleague

12/12 2017

v1.1.2

1.1.2.0 https://github.com/thephpleague/database

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  Sources   Download

MIT

The Requires

 

The Development Requires

database postgres mysql thephpleague

22/11 2017

dev-feature/PLD-2_tests

dev-feature/PLD-2_tests https://github.com/thephpleague/database

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  Sources   Download

MIT

The Requires

 

The Development Requires

database postgres mysql thephpleague

22/11 2017

v1.1.1

1.1.1.0 https://github.com/thephpleague/database

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  Sources   Download

MIT

The Requires

 

The Development Requires

database postgres mysql thephpleague

18/11 2017

v1.1.0

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

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  Sources   Download

MIT

The Requires

 

The Development Requires

database postgres mysql thephpleague

30/09 2017

v1.0.0

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

PHP library and ORM to handle DB connection, apply C.R.U.D. operations

  Sources   Download

MIT

The Requires

 

The Development Requires

database postgres mysql thephpleague