Beispiel #1
0
 public static function update($data, $where)
 {
     self::initDB();
     if (!$where || !$data) {
         self::$errCode = "001";
         self::$errMsg = "参数错误";
         return false;
     }
     //if(is_array($data)){
     //			foreach($data as $key => $val){
     //				$sqlArr[] = $key."='".$val."'";
     //			}
     //		}else{
     //			$sqlArr[] = $data;
     //		}
     //		if(is_numeric($where)){
     //			$whereArr[] = 'id='.$where;
     //		}else if(is_array($where)){
     //			foreach($where as $key => $val){
     //				$whereArr[] = $key."='".$val."'";
     //			}
     //		}else{
     //			$whereArr[] = $where;
     //		}
     $data = array2sql($data);
     $where = array2where($where);
     $sql = 'update ' . self::$tablename . ' set ' . $data . ' where ' . $where;
     //echo $sql."<br />";
     $query = self::$dbConn->query($sql);
     if ($query) {
         return true;
     } else {
         self::$errCode = "002";
         self::$errMsg = "更新数据失败";
         return false;
         //失败则设置错误码和错误信息, 返回false
     }
 }