nextpertise/pdo-bulk

一个PHP Pdo插入包装器,允许您批量插入包含子查询的记录。

dev-master 2015-03-01 19:54 UTC

This package is not auto-updated.

Last update: 2024-09-14 16:24:14 UTC


README

Build Status Scrutinizer Code Quality

一个简单的PHP辅助类,用于处理需要导入数据库的批量数据集。

安装

安装PdoBulk最简单的方法是使用Composer,这个PHP的依赖管理器很棒。安装Composer后,运行composer.phar require nextpertise/pdo-bulk:dev-master,Composer将为您完成所有艰苦的工作。

使用方法

如果您使用的是Composer的自加载器(或者您的框架与之集成),那么您只需要在每个要使用PdoBulk的文件顶部添加一个use PdoBulk\PdoBulk;语句,然后像使用普通类一样使用它。

<?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 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');