forked from fa/breadcrumb-the-shire
38 lines
721 B
PHP
38 lines
721 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace MintyPHP\Repository\Search;
|
||
|
|
|
||
|
|
use MintyPHP\DB;
|
||
|
|
|
||
|
|
class SearchQueryRepository
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @param array<int, mixed> $params
|
||
|
|
* @return array<int, mixed>
|
||
|
|
*/
|
||
|
|
public function selectRows(string $sql, array $params = []): array
|
||
|
|
{
|
||
|
|
if (trim($sql) === '') {
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
|
||
|
|
$rows = DB::select($sql, ...$params);
|
||
|
|
|
||
|
|
return is_array($rows) ? $rows : [];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param array<int, mixed> $params
|
||
|
|
*/
|
||
|
|
public function selectCount(string $sql, array $params = []): int
|
||
|
|
{
|
||
|
|
if (trim($sql) === '') {
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
$value = DB::selectValue($sql, ...$params);
|
||
|
|
|
||
|
|
return (int) ($value ?? 0);
|
||
|
|
}
|
||
|
|
}
|