mrssoft/yii2-db

Yii2 database tools

Installs: 169

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 1

Open Issues: 0

Type:yii2-extension

dev-master 2019-12-18 09:43 UTC

This package is auto-updated.

Last update: 2024-04-18 19:26:13 UTC


README

Batch insert into database.

PHP Github Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist mrssoft/yii2-db "*"

or add

"mrssoft/yii2-db": "*"

to the require section of your composer.json file.

Usage

$batch = new DbBatch();

$batch->add([
    'field1' => $value1,
    'field2' => $value2,
]);

$batch->add([
    'field1' => $value1,
    'field2' => $value2,
], $key)

$batch->addUnique([
    'field1' => $value1,
    'field2' => $value2,
]);

$bool = $batch->insert('{{%table}}', true);
$bool = $batch->replace('{{%table}}');
$batch = new DbBatch([
    'maxItemsInQuery' => 1000,
    'table' => '{{%table}}',
    'truncate' => true,
    'command' => DbBatch::COMMAND_INSERT
]);

$batch->add([
    'field1' => $value1,
    'field2' => $value2,
], $key);

$batch->update([
    'field1' => $value3,
    'field2' => $value4,
], $key);

$count = $batch->getCount();
$keys = $batch->getKeys();
$element = $batch->get($key);
$data = $batch->getData();
$batch->setData($data);

$bool = $batch->execute();