BorysSokolov Posted June 7, 2013 Share Posted June 7, 2013 The below code is part of a function which is supposed to return records from a database but it comes up empty, for some reason. private function _loadEventData($id=NULL){ ...... $sql .= "WHERE `event_start` BETWEEN '$start_date' AND '$end_date' ORDER BY `event_start`"; $stmt = $this->db->prepare($sql); if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_INT); } $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); $stmt->closeCursor(); return $results; } I'm not familiar to using PDO, so I'm not sure where the error lies. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/278878-pdo-returns-empty/ Share on other sites More sharing options...
kicken Posted June 7, 2013 Share Posted June 7, 2013 The simple answer is that your query does not match any rows. Echo out $sql and run it manually to verify it returns data first. Quote Link to comment https://forums.phpfreaks.com/topic/278878-pdo-returns-empty/#findComment-1434589 Share on other sites More sharing options...
Solution BorysSokolov Posted June 8, 2013 Author Solution Share Posted June 8, 2013 I was perplexed because the query worked when I ran it through the console on phpMyAdmin; but as it turns out, I was missing a space in the $sql string. Quote Link to comment https://forums.phpfreaks.com/topic/278878-pdo-returns-empty/#findComment-1434778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.