PHP code example of marekpetras / yii2-merge-table
1. Go to this page and download the library: Download marekpetras/yii2-merge-table library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
marekpetras / yii2-merge-table example snippets
use yii\db\ActiveRecord;
use marekpetras\mergetable\MergeTableTrait;
use marekpetras\mergetable\MergeTableInterface;
class Report extends ActiveRecord implements MergeTableInterface
{
use MergeTableTrait;
/**
* Get the default table name, substitutes the tableName function if not a merge table model
* @return string default table name
*/
public static function defaultTableName()
{
return 'report';
}
}
$id = 15432;
$tableName = Report::ensureExists($id);
$sql = sprintf("
LOAD DATA INFILE '%s'
REPLACE
INTO TABLE `%s`
FIELDS TERMINATED BY ',' ENCLOSED BY '\"'
LINES TERMINATED BY '\n'
", $file, $tableName);
$rows = Yii::$app->db->createCommand($sql)->execute();