<?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"