$time = time() - 60*60*24; // 一天之前的臨時文件
$yesterday = date("Y-m-d H:i:s", $time);
$fileIDs = M("dpp_tmp_page, file")->where("dpp_tmp_page.fileID=file.fileID and file.createDate < '"
. $yesterday . "' and file.status=1")->getField("dpp_tmp_page.fileID", true);
期望查询结果:获取fileID数组。
实际查询结果:sql执行正确,但是查询结果没有fileID,value值是null。
array(43) {
[0] => NULL
[1] => NULL
[2] => NULL
[3] => NULL
[4] => NULL
[5] => NULL
单表查询结果
查询结果:array(43) {
[0] => string(5) "69082"
[1] => string(5) "69088"
[2] => string(5) "69094"
[3] => string(5) "69100"
[4] => string(5) "69106"
[5] => string(5) "69110"
[6] => string(5) "69115"
[7] => string(5) "69121"
[8] => string(5) "69130"
因此,多表查询不要用getField的方式来获取某个field的数组数据。
测试代码
$yesterday = date("Y-m-d H:i:s", $time);
$fileIDs = M("dpp_tmp_page, file")->where("dpp_tmp_page.fileID=file.fileID and file.createDate < '"
. $yesterday . "' and file.status=1")->getField("dpp_tmp_page.fileID", true);
期望查询结果:获取fileID数组。
实际查询结果:sql执行正确,但是查询结果没有fileID,value值是null。
array(43) {
[0] => NULL
[1] => NULL
[2] => NULL
[3] => NULL
[4] => NULL
[5] => NULL
单表查询结果
$r = M("dpp_tmp_page")->getField("fileID", true);
查询结果:array(43) {
[0] => string(5) "69082"
[1] => string(5) "69088"
[2] => string(5) "69094"
[3] => string(5) "69100"
[4] => string(5) "69106"
[5] => string(5) "69110"
[6] => string(5) "69115"
[7] => string(5) "69121"
[8] => string(5) "69130"
因此,多表查询不要用getField的方式来获取某个field的数组数据。
测试代码
public function testGetField()
{
$yesterday = date("Y-m-d H:i:s");
$result = M("dpp_tmp_page, file")->where("dpp_tmp_page.fileID=file.fileID and file.createDate < '"
. $yesterday . "' and file.status=1")->getField("dpp_tmp_page.fileID", true);
echo M()->getLastSql();
dump($result);
$r = M("dpp_tmp_page")->getField("fileID", true);
echo M()->getLastSql();
dump($r);
}