SDb::del PHP Method

del() public method

删除信息,可以连带外键一起删除
public del ( $foreign_info = false )
    public function del($foreign_info = false)
    {
        if (!empty($this->_fields)) {
            $condition = array();
            foreach ($this->_fields as $k => $v) {
                if (!is_object($v)) {
                    $condition[$k] = $v;
                }
            }
            if (!empty($condition)) {
                if ($this->get() !== false) {
                    $result = parent::delete($this->table_name, $condition);
                    if ($result !== false) {
                        if ($foreign_info) {
                            foreach ($this->foreign_keys as $k => $v) {
                                $tmp = explode(".", $v);
                                if (!empty($tmp[0]) && !empty($tmp[1]) && isset($this->_fields->{$k})) {
                                    $tbl_name = trim($tmp[0]);
                                    $condition = array(trim($tmp[1]) => $this->_fields->{$k});
                                    parent::delete($tbl_name, $condition);
                                }
                            }
                        }
                    }
                    return $result;
                }
            }
        }
        return false;
    }