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);
}
?>