thinkphp-Coherent operation-"implementation mechanism"

Source: Internet
Author: User

<?php//Model classes Class Model {//database connection Private $_conn = Null;//where statement Private $_where = null;//table name Private $_tablename = null;//constructor method, receive table name Public function __construct ($tabName) {//Assign value to attribute $this->_tablename = $tabName;//Connect to database $this->_conn = Mysqli_connect (' localhost ', ' root ', ' 12345678 ', ' test ');//Set CharSet encoding mysqli_set_ CharSet ($this->_conn, ' Set names UTF8 ');} The Where method public function where ($whe) {//Determines whether the null value if (empty ($whe)) {$this->_where = NULL;} else {$this->_where = ' whe Re '. $whe;} Return the object return $this;} The Select method Public Function Select () {//stores data $dataarr = Array ();//constructs the SQL statement $sql = ' select * from Tp_ '. Strtolower ($this->_t Ablename). $this->_where;//executes SQL, gets the handle $reshandle = Mysqli_query ($this->_conn, $sql);//Returns the result set while (!! $res = Mysqli_fetch_array ($resHandle, Mysqli_assoc)) {$DATAARR [] = $res;} Return the data return $DATAARR;} The remaining methods, to be supplemented ...} $user = new Model (' user '), $result = $user->where (' ID > ')->select ();p rint_r ($result); 

thinkphp-Coherent operation-"implementation mechanism"

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: 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.