Yii 1.1: rdbcommand

MySQL extention for MULTI INSERT, INSERT IGNORE and INSERT UPDATE
7 followers

RDB

Yii extention for MySQL database with:

  • INSERT INTO table (field) VALUES (1),(2)....
  • INSERT IGNORE
  • INSERT ... ON DUPLICATE KEY UPDATE

Requirements

Install

  • Copy files "RDbCommand.php" and "RDbConnection.php" into your "components" directory.
  • In your main config write in db section 'class' param like this
'db' => array(
        'class' => 'RDbConnection',
        'connectionString' => 'mysql:host=localhost;dbname=database',
        'emulatePrepare' => true,
        'username' => 'root',
        'password' => '',
        'charset' => 'utf8',
        'schemaCachingDuration' => 3600,
        'enableProfiling' => true,
        'tablePrefix' => '',
        'enableParamLogging' => true,
    );

Exemple

MULTI INSERT

Yii::app()->db->createCommand()->insert('table', array(
        array('field'=>1),
        array('field'=>2),
        array('field'=>3),
        array('field'=>4),
        array('field'=>5),
        ...
        array('field'=>'n'),
    ));

INSERT IGNORE ...

Yii::app()->db->createCommand()->insertIgnore('table', array(
        'keyfield'=>1,
        'field'=>0,
    ));

INSERT ... ON DUPLICATE KEY UPDATE

Yii::app()->db->createCommand()->insertUpdate('table', array(
        'keyfield'=>1,
        'field'=>0,
    ), array(
        'field'=>new CDbExpression('field+1'),
    ));

License

rdbcommand is licensed under New BSD license. That allows proprietary use, and for the software released under the license to be incorporated into proprietary products. Works based on the material may be released under a proprietary license or as closed source software. It is possible for something to be distributed with the BSD License and some other license to apply as well.

Total 1 comment

#9945 report it
Rsol at 2012/09/24 11:19am
REPLACE

In github I create new branch "replace". Add REPLACE INTO fuction:

Yii::app()->db->createCommand()->replace('table', array(
        'keyfield'=>1,
        'field'=>0,
    ));

Please, somebody test it.

Leave a comment

Please to leave your comment.

Create extension