我想显示使用的数据库表中存储的数据量 Laravel v 4.2.0但我使用函数count()时遇到问题。这是我的代码:
$total = DB::select("select count(*) from rents left join operators on operators.code = rents.code where (operators.code is null) and rents.booking = 'N'");
echo $total;
消息错误说:
Syntax error or access violation
任何人都可以帮助我吗?
答案 0 :(得分:0)
试试这个:
$total = DB::select(DB::raw("select count(*) as cnt from rents left join operators on operators.code = rents.code where (operators.code is null) and rents.booking = 'N'"));
echo $total[0]->cnt;
尝试调试:
echo "<pre>";
print_r($total);
echo "</pre>";
exit;
看,如果有帮助。