2017 © Pedro Peláez
 

library db-helper

DB helpers to complement phlib/db

image

phlib/db-helper

DB helpers to complement phlib/db

  • Wednesday, April 19, 2017
  • by letssurf
  • Repository
  • 1 Watchers
  • 0 Stars
  • 144 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

phlib/db-helper

Code Checks Codecov Latest Stable Version Total Downloads Licence, (*1)

DB helpers to complement phlib/db, (*2)

Installation

composer require phlib/db-helper

Usage

// Get an Adapter
$config = [
    'host' => 'localhost',
    'username' => 'myuser',
    'password' => 'mypassword',
    'dbname' => 'mydatabase'
];
$db = new \Phlib\Db\Adapter($config);

BulkInsert

Insert and/or update many rows into a table., (*3)

This increases the write performance for adding large numbers (eg. thousands+) of rows, over the typical pseudo-prepared statements used by native PDO., (*4)

$insertFields = [
    'product_id',
    'product_name',
    'product_qty'
];
$updateFields = [
    'product_name',
    'product_qty'
];
$bulkInsert = new BulkInsert($adapter, 'product', $insertFields, $updateFields);

// Many calls to add() will write to the DB in batches
$bulkInsert->add($singleProductData);

// One final manual call to write() to complete
$bulkInsert->write();

QueryPlanner

Test the number of rows that a SELECT statement will query., (*5)

$queryPlanner = new QueryPlanner($adapter, $sqlSelect);
$queryPlanner->getNumberOfRowsInspected(); // eg. 46234

BigResult

Run a SELECT statement which is expected to be slow (eg. >5s) due to quantity of data., (*6)

Query buffering is disabled to reduce the time to first row and avoid consuming PHP's memory for the statement result, and MySQL's query timeout is increased., (*7)

$bigResult = new BigResult($adapter);
$pdoStmt = $bigResult->query($sqlSelect, $bind);

Optionally, prevent very large queries from running by using the QueryPlanner inspection:, (*8)

$bigResult = new BigResult($adapter);
$queryRowLimit = 20000000;
$pdoStmt = $bigResult->query($sqlSelect, $bind, $queryRowLimit);

License

This package is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version., (*9)

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details., (*10)

You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/., (*11)

The Versions

19/04 2017

dev-master

9999999-dev

DB helpers to complement phlib/db

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards
by Chris Minett

helper mysql db

19/04 2017

1.0.1

1.0.1.0

DB helpers to complement phlib/db

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards
by Chris Minett

helper mysql db

13/04 2017

1.0.0

1.0.0.0

DB helpers to complement phlib/db

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards
by Chris Minett

helper mysql db

10/04 2017

dev-feature/replication-monitor

dev-feature/replication-monitor

DB helpers to complement phlib/db

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

by James Dempster
by Luke Richards
by Chris Minett

helper mysql db