public function delete(string $table, array $conditions) : int
{
if (empty($table)) {
throw new \InvalidArgumentException('Table name must be a non-empty string.');
}
if (empty($conditions)) {
// Don't allow foot-bullets
return 0;
}
if (!$this->is1DArray($conditions)) {
throw new \InvalidArgumentException('Only one-dimensional arrays are allowed.');
}
$queryString = 'DELETE FROM ' . $this->escapeIdentifier($table) . ' WHERE ';
// Simple array for joining the strings together
$params = [];
$arr = [];
foreach ($conditions as $i => $v) {
$i = $this->escapeIdentifier($i);
if ($v === null) {
$arr[] = " {$i} IS NULL ";
} elseif ($v === true) {
$arr[] = " {$i} = TRUE ";
} elseif ($v === false) {
$arr[] = " {$i} = FALSE ";
} else {
$arr[] = " {$i} = ? ";
$params[] = $v;
}
}
$queryString .= \implode(' AND ', $arr);
return (int) $this->safeQuery($queryString, $params, \PDO::FETCH_BOTH, true);
}