Home  >  Article  >  Backend Development  >  thinkphp的select跟find的区别

thinkphp的select跟find的区别

WBOY
WBOYOriginal
2016-06-13 12:51:46740browse

thinkphp的select和find的区别

thinkphp是比较好的php开发框架,能比较快速的开发MVC架构的管理系统,我们需要用到 select()和find()方法,两个方法都能返回数据集数组,但有什么不同呢?先看一下我的代码对比:

$tech=M('techlevel','HR_CS_','DB_CONFIG2');
$Data=$tech->where('id=1')->find();
dump($Data);
$Data=$tech->where('id=1')->select();
dump($Data);


结果

array(6) {
  ["ID"] => int(1)
  ["TechLevel"] => string(2) "10"
  ["Remark"] => string(4) "??"
  ["CreateDate"] => string(19) "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) "10"
    ["Remark"] => string(4) "??"
    ["CreateDate"] => string(19) "2013-03-14 15:14:38"
    ["CreateBy"] => string(5) "admin"
    ["ROW_NUMBER"] => string(1) "1"
  }
}


从上面的代码可以看出,find()返回一个一维数组,select()返回一个二维数组,所以在取值时有所不同,一维数组取值用$data["TechLevel"],二维数组取值用$data[0]["TechLevel"],由于一开始没了解这个用法,调试一天也取不值,最后有dump方法才看到两个方法的不同所在!

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn