2013-07-05 5 views
0

DB에서 내 게임에 변수를로드하는 적절한 방법은 무엇입니까?LimeJS에서 DB와 통신하기

Ajax와 Prototype 라이브러리를 사용해 보았지만 작동하지 않습니다. 여기에 내가했던 일이야 : 내 주요의 .js 게임 파일에서

...

var rawVocab = new Array(); 
var optionVocab = new Array(); 

new Ajax.Request('load_vocab.php', { 
    onSuccess : function(xmlhttp) { 
     eval(xmlhttp.responseText); 
    } 
}); 

'load_vocab.php'은 다음과 같습니다 ...

<?php 

header('Content-Type: text/xml'); 
echo '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>'; 

echo '<response>'; 

    $username = "user"; 
    $password = "***************"; 

    try { 
     $conn = new PDO('mysql:host=localhost;dbname=tygrif_school', $username, $password); 
     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

     $stmt = $conn->prepare('SELECT * FROM vocabulary_game WHERE game_type = :game_type'); 
     $stmt->execute(array('game_type' => 'target')); 

     $i=0; 
     while($row = $stmt->fetch()) { 
      echo "rawVocab[".$i."]['word']='".$row['word']."';"; 
      echo "rawVocab[".$i."]['translation']='".$row['translation']."';"; 
      echo "rawVocab[".$i."]['example_sentence_1']='".$row['example_sentence_1']."';"; 
      $i++; 
     } 

     $stmt = $conn->prepare('SELECT * FROM vocabulary_game'); 
     $stmt->execute(array()); 

     $i=0; 
     while($row = $stmt->fetch()) { 
      echo "optionVocab[".$i."]['word']='".$row['word']."';"; 
      echo "optionVocab[".$i."]['translation']='".$row['translation']."';"; 
      echo "optionVocab[".$i."]['example_sentence_1']='".$row['example_sentence_1']."';"; 
      $i++; 
     } 
    } catch(PDOException $e) { 
     echo 'ERROR: ' . $e->getMessage(); 
    } 

echo '</response>'; 

?> 

은 어떤 방법으로 내장 있습니까 Goog 라이브러리에서이를 처리할까요?

답변