0

I want to get matches played between 2 certain dates. In MySQL terminal, I hardcoded the following query and got the following rows returned (to check whether my query is correct)

QUERY

SELECT * FROM schedule WHERE gameDateTime BETWEEN '2020-02-21 00:00:00' AND '2020-02-25 15:15:00' 

enter image description here

HOWEVER, when I run this simple query through PHP I get NO results

PHP CODE

$sql = "SELECT * FROM `schedule` WHERE `gameDateTime` BETWEEN '2020-02-21 00:00:00' AND '2020-02-25 15:15:00'"; $stmnt = $db->prepare($sql); $games = $stmnt->fetchAll(); foreach ($games as $game){ echo $game['homeTeam']; echo 'VS'; echo $game['awayTeam']; echo '<hr />'; } 

DEBUGGING

  • I DID a select(*) to ensure I can retrieve data from my DB
  • gameDateTime IS a datetiime() column

Help appreciated

1
  • 1
    You haven't executed the query. $stmnt->execute() is missing Commented Feb 21, 2020 at 12:01

2 Answers 2

3

You're missing an $stmnt->execute()

Note that you can replace ->prepare with ->query if you wish to run the query immediately rather than preparing it first.

More info: PDO's query vs execute

Sign up to request clarification or add additional context in comments.

Comments

0

You have not executed the query:

$sql = "SELECT * FROM `schedule` WHERE `gameDateTime` BETWEEN '2020-02-21 00:00:00' AND '2020-02-25 15:15:00'"; $stmnt = $db->prepare($sql); $stmnt = $stmnt->execute(); $games = $stmnt->fetchAll(); foreach ($games as $game){ echo $game['homeTeam']; echo 'VS'; echo $game['awayTeam']; echo '<hr />'; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.