[英]request in PhpMyAdmin works, with Laravel Query Builder, doesn't seem to work
I have a problem that I can't fix : 我有一个无法解决的问题:
this request works in PHPMYADMIN 此请求适用于PHPMYADMIN
SELECT cronState.name, command.name, parameter.keyword, eventParameterValue.value
FROM cronState, commandInstance, command, eventParameterValue, parameter
WHERE cronState.id = commandInstance.cronState_id
AND commandInstance.command_id = command.id
AND eventParameterValue.commandInstance_id = commandInstance.id
AND eventParameterValue.parameter_id = parameter.id
AND cronState.id =32
it returns : 它返回:
name name keyword value
on20 DigitalPinSet State 1
on20 PwmPinSet DutyCycle 20
and it's ALL I want. 这就是我想要的。
LITTLE EDIT : I use an AJAX Request(with a state_name) to this method which should returns the query result. 小编辑:我对此方法使用AJAX请求(带有state_name),该方法应返回查询结果。
Now, when I try to implement it with the Laravel Query Builder, it returns some errors. 现在,当我尝试使用Laravel查询生成器实现它时,它将返回一些错误。
My code: 我的代码:
$cronState_id = DB::table('cronState')
->where('name', Input::get('state_name'))
->first();
$cronEvent = DB::table('cronState')
->join('commandInstance', 'commandInstance.cronState_id', '=', 'cronState.id')
->join('command', 'commandInstance.command_id', '=', 'command.id')
->join('eventParameterValue', 'eventParameterValue.commandInstance_id', '=', 'commandInstance.id')
->join('eventParameterValue', 'eventParameterValue.parameter_id', '=', 'parameter.id')
->where('cronState.id', '=', $cronState_id->id)
->select('cronState.name', 'command.name', 'parameter.keyword', 'eventParameterValue.value');
foreach($cronEvent as $result){
$ev = $result['keyword'];
}
return $ev;
The error for this code : 此代码的错误:
{"error":{"type":"ErrorException","message":"Undefined index: keyword","file":"/var/www/stage/app/controllers/EventController.php","line":48}}
{“错误”:{“类型”:“ ErrorException”,“消息”:“未定义索引:关键字”,“文件”:“ / var / www / stage / app / controllers / EventController.php”,“行”: 48}}
if I change 如果我改变
foreach($cronEvent as $result){
$ev = $result['keyword'];
}
return $ev;
to 至
return $cronEvent;
(just delete the foreach loop and rename the returning variable), I have this error : (只需删除foreach循环并重命名返回变量),就会出现此错误:
{"error":{"type":"ErrorException","message":"Object of class Illuminate\\Database\\Query\\Builder could not be converted to string","file":"/var/www/stage/vendor/symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php","line":361}}
{“错误”:{“类型”:“ ErrorException”,“消息”:“ Illuminate \\ Database \\ Query \\ Builder类的对象无法转换为字符串”,“文件”:” / var / www / stage / vendor /symfony/http-foundation/Symfony/Component/HttpFoundation/Response.php","line":361}}
So, how can access to my data in the object ? 那么,如何访问对象中的数据呢? Maybe my Query Builder implementation doesn't works...
也许我的查询生成器实现不起作用...
Thanks for any help ! 谢谢你的帮助 !
There is missing get()
at the end of that query builder, thus you don't run the query at all. 该查询生成器的末尾缺少
get()
,因此您根本不会运行查询。 That's it. 而已。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.