ManaPHP\Db::delete PHP Méthode

delete() public méthode

Deletes data from a table using custom SQL syntax Deleting existing robot $success = $connection->delete( "robots", "id = 101" ); Next SQL sentence is generated DELETE FROM robots WHERE id = 101
public delete ( string $table, string | array $conditions, array $bind = [] ) : integer
$table string
$conditions string | array
$bind array
Résultat integer
    public function delete($table, $conditions, $bind = [])
    {
        if (is_string($conditions)) {
            $conditions = [$conditions];
        }
        $wheres = [];
        /** @noinspection ForeachSourceInspection */
        foreach ($conditions as $k => $v) {
            if (is_int($k)) {
                $wheres[] = Text::contains($v, ' or ', true) ? "({$v})" : $v;
            } else {
                $wheres[] = "`{$k}`=:{$k}";
                $bind[$k] = $v;
            }
        }
        $sql = "DELETE FROM `{$table}` WHERE " . implode(' AND ', $wheres);
        return $this->execute($sql, $bind);
    }