I have seen this and this, but neither of these help my situation, this is why I am knowledgeably opening a question that has been asked before.
My code is:
<?
$getGame = $database->prepare('SELECT * FROM mainSite_games WHERE id=:gameID');
?>
<div class='container_12'>
<div id='contentcont'>
<div id='content'>
<?
if (isset($_GET['gameID'])) {
$getGame->bindValue(':gameID',$GET['gameID'],PDO::PARAM_INT);
$getGame->execute();
$rows = $getGame->fetch(PDO::FETCH_ASSOC);
foreach ($rows as $game) {
$gameName = str_replace(' ','_',strtolower(stripslashes($game['gameName'])));
?>
<section class='<? echo $gameName; ?>'>
<h1><? echo stripslashes($game['gameName']); ?></h1>
<p><? echo stripslashes($game['gameDesc']); ?></p>
<article class='grid_5 alpha' style='float:left;'>
<h3><a href='viewQuests.php?gameID=<? echo $game['id'] ?>'>View <? echo stripslashes($game['gameName']); ?> Quests</a></h3>
<p>Offers the ability to see the available quests in <? echo stripslashes($game['gameName']); ?> along with information about them and a simple guide to go along with each.</p>
</article>
<article class='grid_5 omega' style='float:right;'>
<h3><a href='viewDB.php?gameID=<? echo $game['id'] ?>'>View <? echo stripslashes($game['gameName']); ?> Database</a></h3>
<p>Offers information about <? echo stripslashes($game['gameName']); ?> items, places, and characters. We try to be extensive with our information.</p>
</article>
</section>
<?
}
} else {
echo '<h3>Game ID is not set!</h3>;'
exit();
}
?>
</div>
</div>
</div>
</body>
</html>
<?
$database = null;
unset($database);
?>
The database is initialized and connected to in an include provided by my globhead file:
$function = new srFunc();
try {
$database = new PDO('mysql:host=localhost;dbname=expunged;charset=utf8','expunged','expunged',array(
//database attributes
PDO::ATTR_EMULATE_PREPARES=>false, //use real prepared statements
PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION, //set errors to kill application
PDO::ATTR_PERSISTENT=>true //keep the connection open indefinitely
));
} catch (PDOException $e) {
$function->logPDO($e->getMessage());
exit();
}
logPDO is provided by my functions class:
public function logPDO($err) {
try {
$filename = 'logPDO';
$filehandle = fopen($filename, 'a');
fwrite($filehandle,'[ '.date('Y-m-d Ga e').' ] '.$err."\n\n");
fclose($filehandle);
} catch (exception $e) {
return $e;
}
}
OK..so now we know how my code works -- in the uppermost code box at my foreach, it reports in my error log:
Invalid argument supplied for foreach
Now, changing the line just above ($rows = $getGame->fetch(PDO::FETCH_ASSOC)
) to $rows = $getGame->fetchAll(PDO::FETCH_ASSOC)
(adding All), nothing is reported. It just becomes a blank page with my styling and structure intact.
I'm not sure what's going on, and I am very new to PDO, so I'm not sure how to troubleshoot this.
I have tried wrapping this in a try,catch block but nothing was reported (nor logged to file using my log function), so I'm at a loss. Does anyone with more experience with PDO see anything that's wrong with my code?