27 Dec 2016

Yii DB Commend Tricks

To Truncate Table

Yii::$app->db->createCommand()->truncateTable('tbl_table1')->execute();

To Execute SP

 Yii::$app->db->createCommand("CALL vendor_file_upload();")->execute();

Bulk Insert in CSV File
$qry = "LOAD DATA INFILE '/path/store.csv'
INTO TABLE `tbl_table2`
FIELDS TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS ";
            Yii::$app->db->createCommand($qry)->execute();



public function getDeffData() {
        $data = Yii::$app->db->createCommand("CALL getDeffData();")->queryAll();
        return count($data) ? $this->getDeffDataObj($data) :[];
    }

No comments:

Post a Comment