Sono un novizio di PHP/SQL e sto cercando di utilizzare una variabile all'interno di un heredoc in quanto ho bisogno di un sacco di testo. Ho incluso solo la prima frase in quanto è sufficiente per mostrare il problema).Utilizzare la variabile all'interno di heredoc in PHP (pratica SQL)
Il mio problema è che all'interno di heredoc, le variabili (vedi sotto: $data['game_name]
e $data['game_owner']
) non sono riconosciute come variabili ma come testo normale. Come posso risolvere questo?
<?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());
}
?>
Qualsiasi aiuto sarebbe molto apprezzato.
si sta utilizzando [NOWDOC] (http://php.net/nowdoc) non HEREDOC – Gordon