Soy un novato en PHP/SQL y estoy tratando de usar una variable dentro de un heredoc ya que necesito usar mucho texto. Solo he incluido la primera oración porque es suficiente para mostrar el problema).Usar la variable dentro de heredoc en PHP (práctica SQL)
Mi problema es que dentro del heredoc, las variables (ver a continuación: $data['game_name]
y $data['game_owner']
) no se reconocen como una variable sino como texto sin formato. ¿Como puedo resolver esto?
<?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());
}
?>
Cualquier ayuda sería muy apreciada.
estás usando [NOWDOC] (http://php.net/nowdoc) no HEREDOC – Gordon