我是PHP / SQL的新手,我正在尝试在heredoc中使用一个变量,因为我需要很多文本。我只包括第一句话,足以显示问题)。
我的问题是,在heredoc中,变量(见下文:$ data [‘game_name]和$ data [‘game_owner’])不被识别为一个变量,而是作为纯文本。我该如何解决?
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 <<
Game: $data['game_name]
the owner of the game is $data['game_owner']
EX;
}
//i end the sql request
$response->closeCursor();
}
catch (Exception $e)
{
die('Error: '.$e->getMessage());
}
?>
任何帮助将不胜感激。