Skip to content

kozhemin/yii2-insert-update-behavior

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

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)

About

Yii2 Insert Update Behavior

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages