PHP code example of marsapp / sqlhelper-yii2
1. Go to this page and download the library: Download marsapp/sqlhelper-yii2 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/ */
marsapp / sqlhelper-yii2 example snippets
batchUpdate($table, $columns, $rows, $conditionArray, $conditionColumn) : \yii\db\Command
// Create SqlHelper Object
$sqlHelper = new \marsapp\helper\sql\SqlHelper();
// Setting batch update data
$query = $sqlHelper->batchUpdate('account', ['c_name', 'age'], [
['Mars', 35],
['Gunter', 24],
['Molly', 25],
],[ 1, 2, 3],'id');
// Run batch update
$data = $query->execute();
// Echo last query statement
echo $quiery->getRawSql();
echo "\n";
var_export($data);
whereInChunk($fieldName, $fieldList, $query, $size) : ActiveQuery
// Setting Arguments
$fieldName = 'pkey';
$fieldList = [1, 2, 3, 4];
$query = ActiveRecord::find();
$size = 3;
$data = \marsapp\helpers\sql\SqlHelper::whereInChunk($fieldName, $fieldList, $query, $size)
->asArray()
->all();
// Print Query Syntax
echo $query->createCommand()->sql;
echo "\n";
echo $query->createCommand()->getRawSql();
echo "\n";
// Print Data
var_export($data);
timeIntersect($sCol, $eCol, $sDate, $eDate, $query) : ActiveQuery
// Setting Arguments
$sCol = 'start_date';
$eCol = 'endd_date';
$sDate = '2020-04-01';
$eDate = '2020-04-30';
// Sql Builder
$query = ActiveRecord::find();
$data = \marsapp\helpers\sql\SqlHelper::timeIntersect($sCol, $eCol, $sDate, $eDate, $query)
->asArray()
->all();
// Print Query Syntax
echo $query->createCommand()->sql;
echo "\n";
echo $query->createCommand()->getRawSql();
echo "\n";
// Print Data
var_export($data);
SELECT * FROM `TABLE_NAME`
WHERE NOT
(
(`start_date` > '2020-04-30') OR(
(`endd_date` < '2020-04-01') AND(`endd_date` <> '0000-00-00')
)
)