Mysql显示我的记录数为50000
但是当我检查count($results);
时,它显示我的结果是空的。
这很奇怪,当我遍历结果集时,我也会循环遍历50000条记录。
所以我在想:
以下是我的代码:
<?php
$query = "SELECT
*,
pl.user_id
FROM
passengers_log as pl
join
tabel2 as t2
ON t2.id = t1.id
Join
tabel3 as t3
ON t3.id = t2.id
Join
tabel4 as t4
ON t4.id = t3.id
Join
tabel5 as t5
ON t5.id = t4.id
Join
tabel6 as t6
ON t6.id = t5.id
Join
tabel7 as t7
ON t7.id = t6.id
WHERE
pl.status = '1'
and pl.reply = 'A'
and pl.createdate >= '2016-11-01 00:00:00'
and pl.createdate <= '2016-11-23 14:19:41'
order by
pl.passengers_log_id desc";
$results = Db::query(Database::SELECT, $query)->execute()->as_array();
print_r($results);//returns 50000
count($results);//it returns empty results
?>
PS:我执行查询时得到50000条记录。在PHP中它返回50000个数组结果,所以这个工作正常。但是在php count($result);
中没有给我任何东西,而不是50000它显示空结果。
答案 0 :(得分:0)
Kohana数据库查询结果提供了count
方法。试试这个:
$result = Db::query(Database::SELECT, $query)->execute();
print 'Number of results is: '.$result->count();
答案 1 :(得分:0)
您可能在编写查询以从数据库获取结果时遇到任何错误,否则count始终会给出从数据库返回的行数。