• php数据库操作类


    <?php
    	/*==================================================================*/
    	/*		文件名:BaseLogic.class.php                          */
    	/*		概要: 数据处理公共类.                	       	    */
    
    	class BaseLogic extends MyDB {
    		protected $tabName;		//表的名称
    		protected $fieldList;	//字段集合
    		protected $messList;
    
    		//==========================================
    		// 函数: add($postList)
    		// 功能: 添加
    		// 参数: $postList 提交的变量列表
    		// 返回: 刚插入的自增ID
    		//==========================================
    		function add($postList) {
    			$fieldList='';
    			$value='';
    			foreach ($postList as $k=>$v) {
    				if(in_array($k, $this->fieldList)){
    					$fieldList.=$k.",";
    					if (!get_magic_quotes_gpc())
    						$value .= "'".addslashes($v)."',";
    					else
    						$value .= "'".$v."',";
    				}
    			}
    
    			$fieldList=rtrim($fieldList, ",");
    			$value=rtrim($value, ",");
    
    			$sql = "INSERT INTO {$this->tabName} (".$fieldList.") VALUES(".$value.")";
    			echo $sql;
    			$result=$this->mysqli->query($sql);
    			if($result && $this->mysqli->affected_rows >0 ) 
    				return $this->mysqli->insert_id;
    			else
    				return false;
    		}
    
    
    		//==========================================
    		// 函数: mod($postList)
    		// 功能: 修改表数据
    		// 参数: $postList 提交的变量列表
    		//==========================================
    		function mod($postList) {
    			$id=$postList["id"];
    			unset($postList["id"]);
    			$value='';
    			foreach ($postList as $k=>$v) {
    				if(in_array($k, $this->fieldList)){
    					if (!get_magic_quotes_gpc())
    						$value .= $k." = '".addslashes($v)."',";
    					else
    						$value .= $k." = '".$v."',";
    				}
    			}
    			$value=rtrim($value, ",");
    			$sql = "UPDATE {$this->tabName} SET {$value} WHERE id={$id}";
    			return $this->mysqli->query($sql);	
    		}
    	
    		//==========================================
    		// 函数: del($id)
    		// 功能: 删除
    		// 参数: $id 编号或ID列表数组
    		// 返回: 0 失败 成功为删除的记录数
    		//==========================================
    		function del($id) {
    			if(is_array($id))
    				$tmp = "IN (" . join(",", $id) . ")";
    			else 
    				$tmp = "= $id";
    			
    			$sql = "DELETE FROM {$this->tabName} WHERE id " . $tmp ;
    			return $this->mysqli->query($sql);	
    		
    		}
    
    		
    		function get($id) {
    			$sql = "SELECT * FROM {$this->tabName} WHERE id ={$id}";
    			
    			$result=$this->mysqli->query($sql);
    
    			if($result && $result->num_rows ==1){
    				return $result->fetch_assoc();
    			}else{
    				return false;
    			}
    	
    		}
    		function getMessList(){
    			$message="";
    			if(!empty($this->messList)){
    				foreach($this->messList as $value){
    					$message.=$value."<br>";
    				}
    			}
    			return $message; 	
    		}
    	}
    ?>
    

  • 相关阅读:
    从零开始,开发一个 Web Office 套件(8):状态管理 & 拖动鼠标选中文字
    从零开始,开发一个 Web Office 套件(9):拖动鼠标选中文字 Edge Case
    从零开始, 开发一个 Web Office 套件 (1): 富文本编辑器
    从零开始,开发一个 Web Office 套件(6):光标 & Click 事件
    20211912 202120222 《网络攻防实践》第一周作业
    3天实践亲测简约靠谱Win10linux子系统Ubuntu下显示图形界面搭建固定IP远程服务器
    安卓通知转发
    RocketMQ(8) 消费幂等
    RocketMQ(5) 订阅关系的一致性规范
    RocketMQ(10) 消息类型
  • 原文地址:https://www.cnblogs.com/zhujunxxxxx/p/3344854.html
Copyright © 2020-2023  润新知