nextpertise / pdo-bulk
A PHP Pdo insert wrapper which allows you to bulk insert records wich contain subqueries.
dev-master
2015-03-01 19:54 UTC
This package is not auto-updated.
Last update: 2024-10-26 16:57:40 UTC
README
Simple PHP helper class for working with bulk sets of data which needs to be imported in the database.
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.
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:
<?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
// 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');