PHP Red Bean Not returning correct result

843 Views Asked by At

I have 3 tables.

Episode, Season, Episode_Season

I have made a view as such

"CREATE VIEW episode_season_view AS SELECT * FROM episode
INNER JOIN episode_season ON episode.id = episode_season.episode_id
INNER JOIN season ON season.id = episode_season.season_id";

Which btw works like a charm... Now when I run this query in MysqlWorkbench

"SELECT * FROM season_episode_view
WHERE first_aired > CURDATE() AND season_id = 600";

it returns the correct result. But when i do this,

R::getRow("SELECT * FROM season_episode_view
WHERE first_aired > ? AND season_id = ?", array(date('Y-m-d'), $season_id));

it returns 0 rows... and I cant understand why?

1

There are 1 best solutions below

5
On

This is just a guess, but rather than using PHP's date functions, use Redbean's MySQL functions and possibly getAll():

$results=R::getAll("SELECT * FROM season_episode_view 
WHERE first_aired > ? AND season_id = ?", array(R::$f->curdate(), $season_id));

If that doesn't work, you can try the built in querying:

$row=R::$f->begin()
  ->select('*')->from('season_episode_view')
  ->where(' first_aired > ? AND season_id = ?')->put(R::$f->curdate(),$season_id)
  ->get('row');

Only other thing I can think of is that the first_aired column doesn't like PHP's date() for some reason, possibly due to the field type?