1. Go to this page and download the library: Download mheads/yii2-data-db 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/ */
mheads / yii2-data-db example snippets
use Mheads\Yii2DataDb\QueryDataReader;
use yii\db\Query;
use Yiisoft\Data\Reader\Filter\Equals;
use Yiisoft\Data\Reader\Sort;
$reader = new QueryDataReader(
query: (new Query())->from('product'),
db: Yii::$app->db,
sort: Sort::only(['id'])->withOrderString('-id'),
filter: new Equals('category', 'mobile'),
);
$rows = iterator_to_array($reader->read(), false);
$count = $reader->count();
$reader = new QueryDataReader(
query: Product::find(),
);
$reader = new QueryDataReader(
query: $query,
db: Yii::$app->db,
fieldMap: [
'createdAt' => 'created_at',
'total' => new yii\db\Expression('COUNT(*)'),
],
);
use Mheads\Yii2DataDb\ConditionFilter;
$reader = $reader->withFilter(
new ConditionFilter(['or', ['status' => 'new'], ['status' => 'paid']]),
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.