diff --git a/src/Dibi/DataSource.php b/src/Dibi/DataSource.php index 2496ce32..d7492ae2 100644 --- a/src/Dibi/DataSource.php +++ b/src/Dibi/DataSource.php @@ -161,7 +161,7 @@ class DataSource implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, null if no next record + * @return mixed value on success, false if no next record */ public function fetchSingle() { diff --git a/src/Dibi/Fluent.php b/src/Dibi/Fluent.php index fc70e342..f70bbcc5 100644 --- a/src/Dibi/Fluent.php +++ b/src/Dibi/Fluent.php @@ -311,7 +311,7 @@ class Fluent implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, null if no next record + * @return mixed value on success, false if no next record */ public function fetchSingle() { diff --git a/src/Dibi/Result.php b/src/Dibi/Result.php index 3067460b..8a150673 100644 --- a/src/Dibi/Result.php +++ b/src/Dibi/Result.php @@ -179,13 +179,13 @@ class Result implements IDataSource /** * Like fetch(), but returns only first field. - * @return mixed value on success, null if no next record + * @return mixed value on success, false if no next record */ final public function fetchSingle() { $row = $this->getResultDriver()->fetch(true); if ($row === null) { - return null; + return false; } $this->fetched = true; $this->normalize($row); diff --git a/tests/dibi/Connection.fetch.phpt b/tests/dibi/Connection.fetch.phpt index 7b2a01e8..6bd91166 100644 --- a/tests/dibi/Connection.fetch.phpt +++ b/tests/dibi/Connection.fetch.phpt @@ -18,6 +18,9 @@ $conn->loadFile(__DIR__ . "/data/$config[system].sql"); // fetch a single value $res = $conn->query('SELECT [title] FROM [products] ORDER BY [product_id]'); Assert::same('Chair', $res->fetchSingle()); +Assert::same('Table', $res->fetchSingle()); +Assert::same('Computer', $res->fetchSingle()); +Assert::false($res->fetchSingle()); // fetch complete result set