thinkphp the difference between Select and find (RPM)

Source: Internet
Author: User
Tags vars

Do ordinary PHP project to thinkphp, the field automatically complete match, Ajax when the foreground data is not available, after the discovery is the select and find return data sets are different, refer to the following method modification.

$this->ajaxreturn ($msg [0]); Select returns a two-dimensional array, and find returns a one-dimensional array.

Thinkphp is a good PHP development framework, can be more rapid development of the MVC architecture Management System, we need to use the Select () and the Find () method, two methods can return the array of datasets, but what is the difference? Let's take a look at my code comparison:

[PHP]View Plaincopy print?
    1. $tech =m (' techlevel ',' Hr_cs_ ',' db_config2 ');
    2. $Data =$tech->where (' id=1 ')->find ();
    3. Dump ($Data);
    4. $Data =$tech->where (' id=1 ')->select ();
    5. Dump ($Data);
$tech =m (' techlevel ', ' Hr_cs_ ', ' db_config2 '); $Data = $tech->where (' id=1 ')->find ();d UMP ($Data); $Data = $tech- >where (' id=1 ')->select ();d UMP ($Data);

Results

[PHP]View Plaincopy print?
  1. Array (6) {
  2. ["ID"] = + int (1)
  3. ["techlevel"] = + string (2) "Ten"
  4. ["Remark"] = + string (4) "??"
  5. ["createdate"] = + string (+) "2013-03-14 15:14:38"
  6. ["CreateBy"] = + string (5) "admin"
  7. ["row_number"] = + string (1) "1"
  8. }
  9. Array (1) {
  10. [0] = = Array (6) {
  11. ["ID"] = + int (1)
  12. ["techlevel"] = + string (2) "Ten"
  13. ["Remark"] = + string (4) "??"
  14. ["createdate"] = + string (+) "2013-03-14 15:14:38"
  15. ["CreateBy"] = + string (5) "admin"
  16. ["row_number"] = + string (1) "1"
  17. }
  18. }
Array (6) {  ["ID"] = + int (1)  ["techlevel"] = + string (2) "Ten"  ["Remark"] + string (4) "??"  ["createdate"] = + string (+) "2013-03-14 15:14:38"  ["CreateBy"] + string (5) "admin"  ["row_number"] = > string (1) "1"}array (1) {  [0] = = Array (6) {    ["ID"] = = Int (1)    ["Techlevel"] + string (2) "Ten" 
   ["Remark"] + string (4) "??"    ["createdate"] = + string (+) "2013-03-14 15:14:38"    ["CreateBy"] + string (5) "admin"    ["row_number"] = > string (1) "1"}  }

As can be seen from the above code, find () returns a one-dimensional array, select () returns a two-dimensional array, so when the value is different, one-dimensional array value with $data["Techlevel", the two-dimensional array value with $data[0]["Techlevel"], because at first did not understand this usage, debugging day is not worth, finally have the dump method to see the difference of two methods!

thinkphp the difference between Select and find (RPM)

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: info-contact@alibabacloud.com 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.