MySQL class entire comment

Source: Internet
Author: User
Tags php tutorial rtrim
Configuration Files Section

 
Class
  conn = new mysqli ($host, $username, $passwd);        $this->selectdb ($dbname);    $this->coding ($COD);    }//Set the encoding format public function coding ($cod) {mysql_query ("set CHARACTER set". $cod);    //Read a library public function Selectdb ($dbname) {mysql_select_db ($dbname, $this->conn); }//What fields do you want to query? The last step of the query public function Select ($field = "*") {$this->sql = "select". $field. ' From '. $thi    S->datatable. $this->where. $this->limit;        }//which table to use public function table ($tableName) {$this->datatable = $tableName;    return $this;        }//Perform operation public Function query () {$res = mysql_query ($this->sql); is the resource type that represents the query return result array if (Is_resource ($res)) {//returns a two-dimensional array while ($row = MYSQL_FETCH_ASSOC ($r            ES) {$arr [] = $row;   }//Returns a one-dimensional array of foreach ($arr as $key = = $value) {$ke = $value;         } return $ke;        }}//Get several values for the limit public function limit ($limit) {$this->limit = ' limit '. $limit;    return $this;        The//where condition public function where ($where) {$this->where = ' where '. $where;    return $this;            }//insert Public Function Insert ($insert) {//If it is an indexed array if ($this->is_assoc ($insert)) {            Gets the array key, which is the field value $key = Array_keys ($insert);            $value = Array_values ($insert); For ($i =0, $j =0; $i
  
   
sql = "INSERT INTO". $this->datatable. "        ($col) VALUES ($value) ";            }else{//If it is not an indexed array, convert the array directly to a string $value = Implode (', ', $insert);        $this->sql = "INSERT into". $this->datatable. "VALUES ($value)"; }}//Modify Public Function Update ($update) {foreach ($update as $key = = $value) {$dat a.= $key. "        = ". $value. ', ';        } $values = RTrim ($data, ', '); $this->sql = "UPDATE". $this->datatable. "    SET $values ". $this->where;    }//Delete public Function Delete () {$this->sql = ' Delete from '. $this->datatable. $this->where; }//Determines whether the index array public function IS_ASSOC ($array) {if (Is_array ($array)) {$keys = Array_keys ($array)            ;        return $keys! = Array_keys ($keys);    } return false; }}//$b = Array (' CategoryID ' =>9, ' Name ' =>11, ' Description ' =>22, ' priority ' =>35);//$b = Array (4,5,6,7);//$a = new mysqli ();//query//$sql = $aTable ("Guagua_category")->where (' categoryid=1 ')->limit (3)->select ()//$arr = $a->query ();//insert//$sql = $a->table ("Guagua_category")->insert ($b);//$a->query ();//modify//$sql = $a->table ("guagua_category")- >where ("categoryid=1")->update ($b);//$a->query ();//delete//$sql = $a->table ("guagua_category")->where ("categoryid=9")->delete ();//$a->query ();
  

The above describes the MySQL class throughout the comments, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.