Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zero-archive/yii-insertupdate-behavior
The Yii InsertUpdateCommandBehavior extension adds up some functionality to the default possibilites of yii´s CDbCommand implementation.
https://github.com/zero-archive/yii-insertupdate-behavior
mysql php yii yii-framework
Last synced: 6 days ago
JSON representation
The Yii InsertUpdateCommandBehavior extension adds up some functionality to the default possibilites of yii´s CDbCommand implementation.
- Host: GitHub
- URL: https://github.com/zero-archive/yii-insertupdate-behavior
- Owner: zero-archive
- License: mit
- Archived: true
- Created: 2012-11-01T07:33:06.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-04-30T07:42:17.000Z (over 8 years ago)
- Last Synced: 2024-09-23T22:02:47.845Z (4 months ago)
- Topics: mysql, php, yii, yii-framework
- Language: PHP
- Homepage: https://github.com/dotzero/yii-insertupdate-behavior
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yii InsertUpdateCommandBehavior
[![Latest Stable Version](https://poser.pugx.org/dotzero/yii-insertupdate-behavior/version)](https://packagist.org/packages/dotzero/yii-insertupdate-behavior)
[![License](https://poser.pugx.org/dotzero/yii-insertupdate-behavior/license)](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:
- [Yii Framework](https://github.com/yiisoft/yii) 1.1.14 or above
- [Composer](http://getcomposer.org/doc/)## Install
### Via composer:
```bash
$ composer require dotzero/yii-insertupdate-behavior
```### Add vendor path and import path to your configuration file:
```php
'aliases' => array(
...
'vendor' => realpath(__DIR__ . '/../../vendor'),
),
'import' => array(
...
'vendor.dotzero.yii-insertupdate-behavior.*',
),
```## Basic usage:
```php
$command = Yii::app()->db->createCommand();
$command->attachBehavior('InsertUpdateCommandBehavior', new InsertUpdateCommandBehavior);
$command->insertUpdate('tbl_user', array(
'name'=>'Tester',
'email'=>'[email protected]',
'counter'=>'1'
), array(
'name'=>'Tester',
'email'=>'[email protected]'
));
```Creates and executes an `INSERT` with `ON DUPLICATE KEY UPDATE` **MySQL** statement
```sql
INSERT INTO `tbl_user` (`name`, `email`, `counter`)
VALUES ('Tester', '[email protected]', 1)
ON DUPLICATE KEY UPDATE `name`='Tester', `email`='[email protected]';
```## Advanced usage:
```php
$command = Yii::app()->db->createCommand();
$command->attachBehavior('InsertUpdateCommandBehavior', new InsertUpdateCommandBehavior);
$command->insertUpdate('tbl_user', array(
'name'=>'Tester',
'email'=>'[email protected]',
'counter'=>'1'
), array(
'name'=>'Tester',
'email'=>'[email protected]'
'counter'=>new CDbExpression('LAST_INSERT_ID(counter)');
));
```Creates and executes an `INSERT` with `ON DUPLICATE KEY UPDATE` **MySQL** statement
```sql
INSERT INTO `tbl_user` (`name`, `email`, `counter`)
VALUES ('Tester', '[email protected]', 1)
ON DUPLICATE KEY UPDATE `name`='Tester', `email`='[email protected]', `counter`=LAST_INSERT_ID(counter);
```## License
Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php