Database configuration
In the TP framework to connect to the database operation, to be configured
To find the "database Configuration" in convertion.php and copy it to the Project Profile config.php
Model Layer Production
model: one for each table in the database
The class name is the name of the table, and the member variable inside the class is the column name
A table corresponds to a class where one data corresponds to an object
If we don't have a special operation on the model of the table, we don't have to build it.
Now we're going to make one of the simplest model models InfoModel.class.php
<?phpnamespace Home\model; Namespaces use Think\model under the Model folder in home; Parent class file in thinkphp/library/think/model.class.php class Infomodel extends model{}
Three instances of model mode
Instantiate the Model class //new namespace \model\-name ()//$info = new \home\model\infomodel (); Var_dump ($info);//$info =d ("info"); D ("model Mark")//var_dump ($info); $car =m ("car"); M ("Data sheet mark");//var_dump ($car);
Querying the database
Var_dump ($car->select ());//query, return data of two-dimensional array of the situation//$attr = $car->where ("brand= ' b002 '")->select ();// The Where method can add a query condition//$attr = $car->table ("Nation")->select ();//table method toggles the action table//$attr = $car->field ("Code,name") ->select ();//field can specify the field of the query//$attr = $car->order ("Oil desc")->select ();//Sort/$attr = $car->limit (2,2)- >select ();//paged query, if a parameter n represents the first n, if the two parameter m,n means skip the first m, take N. $attr = $car->page (3,2)->select ();//paging, two parameters m,n for page m, n data//$attr = $car->field ("brand,count (*)") Group ("brand")->select ();//Group Query//select * FROM info join nation on condition;//$attr = $car->join ("Brand on car.brand= Brand.brand_code ")->select ();//Connection query//$attr = $car->distinct (true)->field (" brand ")->select ();//go to re-query// $attr = $car->find ("c001"), a single-dimensional array is returned based on the primary key, the primary key value is not written, the first//$attr = $car->select ("c001,c002") is returned by default, and/or based on the primary key value query, Returns a two-dimensional array $attr= $car->where ("name like '% Audi% '")->order ("Powers desc")->select (); $this->assign ("Shuzu", $ attr); $this->display ()
thinkphp Explanation (v)--database configuration and model data models layer, query