PHP data processing public class
Release: 2016-07-25 08:45:37
Original
1430 people have browsed it
- /*======================================== ===========================*/
- /* 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
|
php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
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