thinkphp是比较好的php开发框架,能比较快速的开发MVC架构的管理系统,我们需要用到 select()和find()方法,两个方法都能返回数据集数组,但有什么不同呢?先看一下我的代码对比:
- $Data=$test->where('id=1')->find();
- var_dump($Data);
- $Data=$test->where('id=1')->select();
- var_dump($Data);
$tech=M('techlevel','HR_CS_','DB_CONFIG2');
$Data=$tech->where('id=1')->find();
dump($Data);
$Data=$tech->where('id=1')->select();
dump($Data);
结果
- ["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"
- }
- }
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方法才看到两个方法的不同所在!