清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | <?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 ; } } ?> |