I am making a call to the database to fetch some data. I have tried the request in SQL, and it works fine. I have coded the query using PDO, and it works fine. But using RedBeanPHP with the same query only returns one result.
$app->get('/shoutbox/new/:msgid', function ($msgid) use ($app) {
$messages = R::findAll('shoutbox_message', ' WHERE message_id > ? LIMIT 10', array($msgid));
$app->response()->header('Content-Type', 'application/json');
var_dump($messages);
echo json_encode(R::exportAll($messages));
});
I have used var_dump($messages)
to verify there's only one message being returned.
I found a similar problem here, but the OP solved it without explaining how: sql query using redbeans php
Any advice?
You are using R::findAll
which is used for when you do not want to add any conditions. However, you have a WHERE condition in your query. You want to use the R::find
method instead.
I'm not sure what value is being passed is in your $msgid parameter or what the resulting $messages should contain, but the query would look like this.
$messages = R::find('shoutbox_message', ' message_id = ? LIMIT 10', array($msgid) );