I'm a newbie to PHP/SQL and I am trying to use a variable within a heredoc as I need to ut a lot of text. I've only included the first sentence as it is enough to show the problem).
My problem is that within the heredoc, the variables (see below: $data['game_name]
and $data['game_owner']
) are not recognized as a variable but as plain text. How can I solve this?
<?php
try
{
//i am connecting the the database base mysql 'test'
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=test', 'root', '', $pdo_options);
//the i read the data in the databse 'video_dame'
$response = $bdd->query('SELECT * FROM video_game');
//pour qu'elle soit visible à l'écran, on affiche chaque entrée une à une
while ($data= $response->fetch())
{
echo <<<'EX'
<p>Game: $data['game_name]<br/>
the owner of the game is $data['game_owner']
</p>
EX;
}
//i end the sql request
$response->closeCursor();
}
catch (Exception $e)
{
die('Error: '.$e->getMessage());
}
?>
Any help would be much appreciated.