Kotchasan Framework Documentation
ResultInterface
ResultInterface
\Kotchasan\Result\ResultInterface is the interface for all result types.
Interface Definition
namespace Kotchasan\Result;
interface ResultInterface
{
public function fetch();
public function fetchAll(): array;
public function fetchColumn(int $columnNumber = 0);
public function rowCount(): int;
public function columnCount(): int;
public function getColumnMeta(int $column): array;
public function getResult();
public function isEmpty(): bool;
public function hasMore(): bool;
public function reset(): bool;
public function close(): bool;
public function count(): int;
}Method Reference
fetch()
Fetch the next row from result set.
$result = $query->execute();
$row = $result->fetch(); // object or nullfetchAll()
Fetch all rows as array.
$result = $query->execute();
$rows = $result->fetchAll(); // array of objectsfetchColumn(int $columnNumber = 0)
Fetch single column from the next row.
$result = $db->select('COUNT(*)')->from('user')->execute();
$count = $result->fetchColumn(); // Value of first columnrowCount()
Number of affected rows (for INSERT/UPDATE/DELETE).
$result = $db->update('user')->set(['status' => 0])->where([...])->execute();
echo $result->rowCount(); // Number of updated rowscolumnCount()
Number of columns in result set.
$result = $db->select('id', 'name', 'email')->from('user')->execute();
echo $result->columnCount(); // 3getColumnMeta(int $column)
Get column metadata.
$meta = $result->getColumnMeta(0);
// ['name' => 'id', 'native_type' => 'LONG', ...]getResult()
Get underlying result object.
// PDOResult: returns PDOStatement
// ArrayResult: returns array
$raw = $result->getResult();isEmpty()
Check if result is empty.
if ($result->isEmpty()) {
echo "No data found";
}hasMore()
Check if there are more rows.
while ($result->hasMore()) {
$row = $result->fetch();
}reset()
Reset pointer to the beginning.
$result->fetchAll(); // Read all
$result->reset(); // Reset
$first = $result->fetch(); // Read againclose()
Close cursor and free memory.
$result->close();count()
Alias of rowCount() (for Countable interface).
echo count($result); // If implement Countable
echo $result->count();Implementations
- PDOResult - For PDO queries
- ArrayResult - For cached results