PdoBulk - A PHP Pdo insert wrapper
, (*1)
Simple PHP helper class for working with bulk sets of data which needs to be imported in the database., (*2)
Installing
The easiest way to install PdoBulk is to use Composer, the awesome dependency manager for PHP. Once Composer is installed, run composer.phar require nextpertise/pdo-bulk:dev-master
and composer will do all the hard work for you., (*3)
Usage
If you are using the autoloader in Composer (or your framework ties into it), then all you need to do is add a use PdoBulk\PdoBulk;
statement at the top of each file you wish to use PdoBulk in and use it like a normal class:, (*4)
<?php
namespace exampleApp;
require 'src/PdoBulk/PdoBulk.php';
use PdoBulk\PdoBulk;
use PdoBulk\PdoBulkSubquery;
// configuration
$dbhost = "localhost";
$dbname = "dpkg";
$dbuser = "user";
$dbpass = "password";
// database connection
$conn = new \PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$pdoBulk = new PdoBulk($conn);
Add a two entries, (*5)
// Add entry 1 into `Package`
$packageEntry = array();
$packageEntry['name'] = 'wget';
$packageEntry['description'] = 'retrieves files from the web';
$packageEntry['architecture'] = 'amd64';
$pdoBulk->persist('Package', $packageEntry);
// Add entry 2 into `Package`
$packageEntry = array();
$packageEntry['name'] = 'curl';
$packageEntry['description'] = 'retrieves files from the web';
$packageEntry['architecture'] = 'amd64';
$pdoBulk->persist('Package', $packageEntry);
// Flush records to the database
$pdoBulk->flushQueue('Package');