Skip to content

Latest commit

 

History

History
62 lines (45 loc) · 1.16 KB

README.md

File metadata and controls

62 lines (45 loc) · 1.16 KB

Yii2 Insert Update Behavior

Simple Behavior INSERT ON DUPLICATE KEY UPDATE or INSERT IGNORE

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require kozhemin/yii2-insert-update-behavior:dev-master

or add

"kozhemin/yii2-insert-update-behavior": "dev-master"

to the require section of your composer.json file.

Usage

This behavior allows you to create queries for INSERT ON DUPLICATE KEY UPDATE or INSERT IGNORE

For example:

Attach a new behavior to your model

   public function behaviors()
   {
       return[
            \kozhemin\dbHelper\InsertUpdate::className(),
       ];
   }

usage

   $dataInsert = [ ['title text', 'description'], ['title2 text', 'description2'], ['title3 text', 'descriptio3'] ];
   //Optional column parameter
   $column = ['title', 'description'];
    //INSERT ON DUPLICATE KEY UPDATE
    $model = new Post();
    $model->InsertUpdate($dataInsert, $column)

or

    //INSERT IGNORE
    $model = new Post();
    $model->insertIgnore($dataInsert, $column)