This article mainly introduces the yii database query method, and analyzes the techniques for directly querying and using criteria in combination with instances, for more information about how to query yii databases, see the following example. We will share this with you for your reference. The details are as follows:
Two query methods are described here. One is direct query, and the other is to use criteria for query.
The Code is as follows:
$ User = User: model ();
1. Direct query:
$ Arr = array ("select" => "username, password, email", // the field to be queried "condition" => "username like '% 6 '", // query condition "order" => "id desc", "limit" => 5, "offset" => 1 ,); $ info = $ user-> findAll ($ arr );
2. Use criteria:
$ Criteria = new CDbCriteria (); $ criteria-> select = "username, password, email"; $ criteria-> condition = "username like '% 1 '"; $ criteria-> limit = 5; $ criteria-> order = "id desc"; $ criteria-> offset = 1; $ info = $ user-> findAll ($ criteria );
I hope this article will help you design PHP programs based on the yii framework.