基于php和mysql的简单的dao类实现crud操作功能(2)

public function delete($where) {
            $wheres = $this->_getWhereString($where);
            $sql = "delete from ".$this->_table.$wheres;
            //echo "[delete]".$sql."<br>";
            $result = @mysql_query($sql);
            if (! $result) {
                return -1;
            }
            return @mysql_affected_rows();
        }

protected function _getParamKeyString($params) {
            $keys = array_keys($params);
            return implode(",", $keys);
        }

protected function _getParamValString($params) {
            $vals = array_values($params);
            return "'".implode("','", $vals)."'";
        }

private function _getUpdateString($params) {
            //echo "_getUpdateString";
            $sql = "";
            if (is_array($params)) {
                $sql = $this->_getKeyValString($params, ",");
            }
            return $sql;
        }

private function _getWhereString($params) {
            //echo "_getWhereString";
            $sql = "";
            if (is_array($params)) {
                $sql = " where ";
                $where = $this->_getKeyValString($params, " and ");
                $sql = $sql.$where;
            }
            return $sql;
        }

private function _getKeyValString($params, $split) {
            $str = "";
            if (is_array($params)) {
                $paramArr = array();
                foreach($params as $key=>$val) {
                    $valstr = $val;
                    if (is_string($val)) {
                        $valstr = "'".$val."'";
                    }
                    $paramArr[] = $key."=".$valstr;
                }
                $str = $str.implode($split, $paramArr);
            }
            return $str;
        }

public function release() {
            @mysql_close();
        }
    }

function T($table) {
        return (new SimpleDao())->table($table);
    }
?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/58e1d7e31469b53fd4746ea05ebf9486.html