Skip to content

Commit f3a15cb

Browse files
author
David Nahodyl
committed
added handling for count method
1 parent aac252d commit f3a15cb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/Database/Query/FMBaseBuilder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,5 +716,27 @@ public function setGlobalFields(array $globals){
716716
$this->globalFields = $globals;
717717
return $this->connection->setGlobalFields($this);
718718
}
719+
/**
720+
* Retrieve the "count" result of the query.
721+
*
722+
* @param string $columns
723+
* @return int
724+
*/
725+
public function count($columns = '*')
726+
{
727+
$this->limit(1);
728+
try {
729+
$result = $this->connection->performFind($this);
730+
} catch (FileMakerDataApiException $e){
731+
if ($e->getCode() === 401){
732+
// no records found - this is ok
733+
// return 0
734+
return 0;
735+
}
736+
}
737+
738+
$count = $result['response']['dataInfo']['foundCount'];
739+
return (int) $count;
740+
}
719741

720742
}

0 commit comments

Comments
 (0)