- /*============================== ====================================*/
- /* 檔名: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=rtrimrim ($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."
";
- }
- }
- return $message;
- }
- }
- ?>
複製程式碼
|
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31