Thinkphp is a good php development framework that can quickly develop a management system with MVC architecture. we need to use the select () and find () methods. both methods can return a dataset array.
Thinkphp is a good php development framework that can quickly develop a management system with MVC architecture. we need to use the select () and find () methods. both methods can return a dataset array, but what's the difference? Let's take a look at my code comparison:
- $ Tech = M ('techlevel', 'HR _ CS _ ', 'DB _ config2 ');
- $ Data = $ tech-> where ('Id = 1')-> find ();
- Dump ($ Data );
- $ Data = $ tech-> where ('Id = 1')-> select ();
- Dump ($ Data );
Result
- Array (6 ){
- ["ID"] => int (1)
- ["TechLevel"] => string (2) "10"
- ["Remark"] => string (4) "��"
- ["CreateDate"] => string (19) "2013-03-1415: 14: 38"
- ["CreateBy"] => string (5) "admin"
- ["ROW_NUMBER"] => string (1) "1"
- }
-
- Array (1 ){
- [0] => array (6 ){
- ["ID"] => int (1)
- ["TechLevel"] => string (2) "10"
- ["Remark"] => string (4) "��"
- ["CreateDate"] => string (19) "2013-03-1415: 14: 38"
- ["CreateBy"] => string (5) "admin"
- ["ROW_NUMBER"] => string (1) "1"
- }
- }
From the code above, find () returns a one-dimensional array, and select () returns a two-dimensional array, so the values are different, the value of a one-dimensional array is $ data ["TechLevel"], and the value of a two-dimensional array is $ data [0] ["TechLevel"]. since we didn't understand this usage at the beginning, debugging is not worthwhile for one day. only the dump method can be used to see the difference between the two methods!
In addition,
- $ Model = M ();
- $ SQL = 'selectroleidfrom '. C ("DB_PREFIX"). 'adminwhereuserid ='. session ('userid ').'';
- $ List = $ Model-> query ($ SQL );
-
- // Write method 1
- Foreach ($ listas & $ info ){
- If (info ['roleid'] = '1 '){
- }
-
- // Statement 2
- If ($ list [0] ['roleid'] = '1 '){
- }
The spelling of the original thinkphp SQL is also a two-dimensional array.