PHPackages                             dotzero/yii-insertupdate-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. dotzero/yii-insertupdate-behavior

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

dotzero/yii-insertupdate-behavior
=================================

The Yii InsertUpdateCommandBehavior extension adds up some functionality to the default possibilites of yii´s CDbCommand implementation

v1.0.0(10y ago)137MITPHPPHP &gt;=5.3.0

Since Apr 30Pushed 10y ago1 watchersCompare

[ Source](https://github.com/zero-archive/yii-insertupdate-behavior)[ Packagist](https://packagist.org/packages/dotzero/yii-insertupdate-behavior)[ RSS](/packages/dotzero-yii-insertupdate-behavior/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Yii InsertUpdateCommandBehavior
===============================

[](#yii-insertupdatecommandbehavior)

[![Latest Stable Version](https://camo.githubusercontent.com/7695e7f0a4649f60f4bff89a2819205c02f0bda0052c95b7dcde83794f5965cc/68747470733a2f2f706f7365722e707567782e6f72672f646f747a65726f2f7969692d696e736572747570646174652d6265686176696f722f76657273696f6e)](https://packagist.org/packages/dotzero/yii-insertupdate-behavior)[![License](https://camo.githubusercontent.com/4959c73dddc90d19d3f00f0492a281fbfc7f0a50cacb9aadfb0749ccbbd67c54/68747470733a2f2f706f7365722e707567782e6f72672f646f747a65726f2f7969692d696e736572747570646174652d6265686176696f722f6c6963656e7365)](https://packagist.org/packages/dotzero/yii-insertupdate-behavior)

The **InsertUpdateCommandBehavior** extension adds up some functionality to the default possibilites of yii´s **CDbCommand** implementation. Creates and executes an `INSERT` with `ON DUPLICATE KEY UPDATE` **MySQL** statement.

Requirements:
-------------

[](#requirements)

- [Yii Framework](https://github.com/yiisoft/yii) 1.1.14 or above
- [Composer](http://getcomposer.org/doc/)

Install
-------

[](#install)

### Via composer:

[](#via-composer)

```
$ composer require dotzero/yii-insertupdate-behavior
```

### Add vendor path and import path to your configuration file:

[](#add-vendor-path-and-import-path-to-your-configuration-file)

```
'aliases' => array(
    ...
    'vendor' => realpath(__DIR__ . '/../../vendor'),
),
'import' => array(
    ...
    'vendor.dotzero.yii-insertupdate-behavior.*',
),
```

Basic usage:
------------

[](#basic-usage)

```
$command = Yii::app()->db->createCommand();
$command->attachBehavior('InsertUpdateCommandBehavior', new InsertUpdateCommandBehavior);
$command->insertUpdate('tbl_user', array(
    'name'=>'Tester',
    'email'=>'tester@example.com',
    'counter'=>'1'
), array(
    'name'=>'Tester',
    'email'=>'tester@example.com'
));
```

Creates and executes an `INSERT` with `ON DUPLICATE KEY UPDATE` **MySQL** statement

```
INSERT INTO `tbl_user` (`name`, `email`, `counter`)
VALUES ('Tester', 'tester@example.com', 1)
ON DUPLICATE KEY UPDATE `name`='Tester', `email`='tester@example.com';
```

Advanced usage:
---------------

[](#advanced-usage)

```
$command = Yii::app()->db->createCommand();
$command->attachBehavior('InsertUpdateCommandBehavior', new InsertUpdateCommandBehavior);
$command->insertUpdate('tbl_user', array(
    'name'=>'Tester',
    'email'=>'tester@example.com',
    'counter'=>'1'
), array(
    'name'=>'Tester',
    'email'=>'tester@example.com'
    'counter'=>new CDbExpression('LAST_INSERT_ID(counter)');
));
```

Creates and executes an `INSERT` with `ON DUPLICATE KEY UPDATE` **MySQL** statement

```
INSERT INTO `tbl_user` (`name`, `email`, `counter`)
VALUES ('Tester', 'tester@example.com', 1)
ON DUPLICATE KEY UPDATE `name`='Tester', `email`='tester@example.com', `counter`=LAST_INSERT_ID(counter);
```

License
-------

[](#license)

Licensed under the MIT license:

###  Health Score

26

—

LowBetter than 40% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3752d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/265633?v=4)[dotzero](/maintainers/dotzero)[@dotzero](https://github.com/dotzero)

---

Top Contributors

[![dotzero](https://avatars.githubusercontent.com/u/265633?v=4)](https://github.com/dotzero "dotzero (8 commits)")

---

Tags

mysqlphpyiiyii-frameworkmysqlextensionBehavioryii

### Embed Badge

![Health badge](/badges/dotzero-yii-insertupdate-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/dotzero-yii-insertupdate-behavior/health.svg)](https://phpackages.com/packages/dotzero-yii-insertupdate-behavior)
```

###  Alternatives

[sjaakp/yii2-sortable-behavior

Sort ActiveRecords and related records in Yii2.

36178.2k](/packages/sjaakp-yii2-sortable-behavior)[yiiext/activerecord-relation-behavior

Inspired by and put together the awesomeness of many yii extensions that aim to improve saving of related records. Comes with 100% test coverage and well structured and clean code so it can savely be used in enterprise production enviroment.

9337.9k](/packages/yiiext-activerecord-relation-behavior)[yiiext/migrate-command

This is an enhanced version of the Yii Database Migration Tool that adds module support and many more usefull features.

34175.7k4](/packages/yiiext-migrate-command)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1880.5k1](/packages/sjaakp-yii2-spatial)[nanson/yii2-postgis

Yii2-extension to work with postgis data

1854.2k](/packages/nanson-yii2-postgis)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
