use Friendica\Network\HTTPException\ServiceUnavailableException;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Profiler;
+use InvalidArgumentException;
use mysqli;
use mysqli_result;
use mysqli_stmt;
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
- * @return int
+ * @return int Count of rows
*
* Example:
* $table = "post";
* $count = DBA::count($table, $condition);
* @throws \Exception
*/
- public function count($table, array $condition = [], array $params = [])
+ public function count($table, array $condition = [], array $params = []): int
{
// @TODO Can we dump this to have ": int" as returned type-hint?
if (empty($table)) {
- return false;
+ throw new InvalidArgumentException('Parameter "table" cannot be empty.');
}
$table_string = DBA::buildTableString($table);
$upds = implode(', ', $upd);
- $r = $this->e(sprintf("UPDATE %s SET %s;", $table_name, $upds));
+ $r = $this->e(sprintf("UPDATE %s SET %s;", DBA::quoteIdentifier($table_name), $upds));
if (!$this->isResult($r)) {
throw new \RuntimeException("Failed updating `$table_name`: " . $this->errorMessage());
}