Php 调用未定义的方法/Database/Query/Builder::toArray()
我是使用laravel的新手,我得到了如下错误:Php 调用未定义的方法/Database/Query/Builder::toArray(),php,mysql,database,laravel,laravel-query-builder,Php,Mysql,Database,Laravel,Laravel Query Builder,我是使用laravel的新手,我得到了如下错误: Call to undefined method Illuminate\Database\Query\Builder::toArray() 这是laravel中的查询生成器 $statsMoneyInPlay = DB::table('enginepoker_log.poker') ->selectRaw("SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts)")
Call to undefined method Illuminate\Database\Query\Builder::toArray()
这是laravel中的查询生成器
$statsMoneyInPlay = DB::table('enginepoker_log.poker')
->selectRaw("SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts)")
->selectRaw("sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count(*) As moneyInPlay")
->groupBy("Date(ts)")
->orderBy("Date(ts)")
->toArray();
首先获取()集合,然后将其转换为数组(toArray())
返回一个有说服力的查询生成器实例。这就像是MySQL
query。它实际上不从数据库中获取数据
您需要执行该查询以从数据库中获取数据
这样做。调用get()
函数到雄辩的查询生成器实例
$statsMoneyInPlay = DB::table('enginepoker_log.poker')
->selectRaw("SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts)")
->selectRaw("sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count(*) As moneyInPlay")
->groupBy("Date(ts)")
->orderBy("Date(ts)")
->get()
->toArray();
将其更改为
->get()->toArray()代码>put get(),我得到了如下错误{SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;请查看与您的MariaDB服务器版本对应的手册,以了解在第1行的“SELECT UNIX_TIMESTAMP(Date(ts)*100作为ts)、sum(pot+p1pot+p2pot+p3pot+p4p)”附近使用的正确语法(SQL:选择select UNIX_TIMESTAMP(日期(ts)*100作为ts),sum(pot+p1pot+p2pot+p3pot+p4pot+p5pot+p6pot+p7pot+p8pot+p9pot)/count(*)作为EngineBooker的MoneyInput\u log.poker group by Date(ts)order by Date(ts)asc)}我输入get(),我得到了这样的错误{SQLSTATE[42000]:语法错误或访问冲突:1064您的SQL语法有错误;请查看与您的MariaDB服务器版本相对应的手册,以了解在第1行的“选择UNIX时间戳(日期(ts)*100作为ts)、sum(pot+p1pot+p2pot+p3pot+p4p)”附近使用的正确语法(SQL:选择选择UNIX时间戳(日期(ts)*100作为ts)、sum(pot+p1pot+p2pot+p3pot+p4pot+p5pot+p6pot+p7pot+p8pot+p9pot)/count(*)作为moneyInPlay fromenginepoker\u log
poker
groupbyDate(ts)
order byDate(ts)
asc)}这是来自本机php$statsmoneinplay=array()的查询$sql\u query=“选择UNIX\u时间戳(日期(ts))*1000作为ts,求和(pot+p1pot+p2pot+p3pot+p4pot+p5pot+p6pot+p7pot+p8pot+p9pot)/count(*)作为EngineBooker\u log.poker中的MoneyPlay,其中dealId=“.$session->dealId.”按日期分组(ts)按日期排序(ts)限制30“$resource=sql::query($sql\u query)或者死(mysql_error());
$statsMoneyInPlay = DB::table('enginepoker_log.poker')
->selectRaw("SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts)")
->selectRaw("sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count(*) As moneyInPlay")
->groupBy("Date(ts)")
->orderBy("Date(ts)")
$statsMoneyInPlay = DB::table('enginepoker_log.poker')
->selectRaw("SELECT UNIX_TIMESTAMP(Date(ts)*100 as ts)")
->selectRaw("sum(pot + p1pot + p2pot + p3pot + p4pot + p5pot + p6pot + p7pot + p8pot + p9pot) / count(*) As moneyInPlay")
->groupBy("Date(ts)")
->orderBy("Date(ts)")
->get()
->toArray();