2017 © Pedro Peláez
 

library yii-insertupdate-behavior

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

image

dotzero/yii-insertupdate-behavior

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

  • Saturday, April 30, 2016
  • by dotzero
  • Repository
  • 1 Watchers
  • 1 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Yii InsertUpdateCommandBehavior

Latest Stable Version License, (*1)

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., (*2)

Requirements:

Install

Via composer:

$ composer require dotzero/yii-insertupdate-behavior

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:

$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, (*3)

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:

$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, (*4)

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

Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php, (*5)

The Versions

30/04 2016

dev-master

9999999-dev

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

  Sources   Download

MIT

The Requires

 

by Avatar dotzero

extension yii behavior mysql

30/04 2016

v1.0.0

1.0.0.0

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

  Sources   Download

MIT

The Requires

 

by Avatar dotzero

extension yii behavior mysql