Use variável dentro heredoc em PHP (prática SQL)
Sou novato em PHP / SQL e estou tentando usar uma variável dentro de um heredoc, já que preciso usar muito texto. Eu incluí apenas a primeira sentença, pois é suficiente para mostrar o problema).
Meu problema é que dentro do heredoc, as variáveis (veja abaixo:$data['game_name]
e$data['game_owner']
) não são reconhecidos como uma variável, mas como texto simples. Como posso resolver isso?
<?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());
}
?>
Qualquer ajuda seria muito apreciada.