- /*======================================== ===========================*/
- /* File name: BaseLogic.class.php */
- /* Summary: Data processing public Class. */
-
- class BaseLogic extends MyDB {
- protected $tabName; //The name of the table
- protected $fieldList; //Field collection
- protected $messList;
-
- //============ ===============================
- // Function: add($postList)
- // Function: Add
- // Parameters: $postList Submitted variable list
- // Return: The newly inserted auto-increment 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;
- }
-
-
- //==================================== =======
- // Function: mod($postList)
- // Function: Modify table data
- // Parameter: $postList submitted variable list
- //============ ===============================
- 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);
- }
-
- //======================== ==================
- // Function: del($id)
- // Function: Delete
- // Parameter: $id number or ID list array
- // Return : 0 Failure and success are the number of deleted records
- //======================================== ====
- 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;
- }
- }
- ?>
Copy code
|