2017-05-30 58 views
0

我希望从我的数据库中获取数据并将其插入到数组中以将其传递给我的Android应用程序。数据加以取出:PHP使用fetch()获取值

小屋都是预制造的结构中,符合生态旅游的严格规范,以便保持森林覆盖的原始字符和坚固性。随着汽车停下来,你会发现自己坐落在一个温柔的山坡上,在厚厚的橡树和松树下。欢迎来到西姆拉最好的度假胜地Shoghi的Aamod。 Aamod Shoghi的另一个秘诀就是我们的面包店。新鲜出炉的好吃的香气会唤醒你每一个清醒的时刻。如果您要求我们收拾几个分类以带回家,我们不会感到惊讶。我们自称是所有西姆拉餐厅最好的面包师。 Aamod的一天永远不会没有任何行动。清晨打开窗户,欣赏壮丽的景色和清新的空气。随着这一切开始,你的一天充满了惊喜。在我们广阔的草坪上享用团队早餐,或在我们众多的设施的帮助下玩有趣的团队建设游戏。您可以在我们宽敞的会议室中安排商务活动。当你的团队忙于团队建设活动时,你可以在我们专业维护的小铲和果岭上策划下一场领先的高尔夫球比赛!

但脚本每次崩溃。

$resort_name = $_POST['resort_name']; 

$sql = "SELECT resort_desc from resorts where resort_name = :resort_name"; 
$stmt = $conn->prepare($sql); 
$stmt->bindParam(':resort_name', $resort_name, PDO::PARAM_STR); 
$stmt->execute(); 
if($stmt->rowCount()){ 
    $response["resort_desc"] = array(); 
    $response["resort_desc"][0] = $stmt->fetch(); 
    $response["success"] = 1; 
} else { 
    $response["success"] = 0; 
} 

结果的大小是否太大?如果是的话,我怎么能得到这些数据?

的var_dump( '响应') `

array(1) { 
    array(2) { 
    ["resort_desc"]=> 
    string(1135) "The cottages are all pre-fabricated structures in-line with the strict norms of Ecotourism so as to retain the original character and ruggedness of the forest cover. As the car stops, you�ll find yourself on a gentle hill slope, under a thick cover of oak and pine trees. Welcome to Aamod at Shoghi, the finest resort of Shimla. Another of our best kept secrets at Aamod Shoghi is our bakery. The aroma of freshly baked goodies will entice you every waking hour. We won�t be surprised if you ask us to pack a few assortments to carry back home. We claim to be the best bakers in all of Shimla restaurants. A day at Aamod is never without action. Open your windows early morning for a majestic view and fresh air. And with this begins your day full of surprises. Have team breakfast in our sprawling lawns or play interesting team building games with the help of our multitude of facilities. You can have Business retreats in our spacious conference rooms. While your team is busy at team building activities you can plan your next leadership retreat over a game of golf on our professionally maintained chipping and putting greens!" 

    string(1135) "The cottages are all pre-fabricated structures in-line with the strict norms of Ecotourism so as to retain the original character and ruggedness of the forest cover. As the car stops, you�ll find yourself on a gentle hill slope, under a thick cover of oak and pine trees. Welcome to Aamod at Shoghi, the finest resort of Shimla. Another of our best kept secrets at Aamod Shoghi is our bakery. The aroma of freshly baked goodies will entice you every waking hour. We won�t be surprised if you ask us to pack a few assortments to carry back home. We claim to be the best bakers in all of Shimla restaurants. A day at Aamod is never without action. Open your windows early morning for a majestic view and fresh air. And with this begins your day full of surprises. Have team breakfast in our sprawling lawns or play interesting team building games with the help of our multitude of facilities. You can have Business retreats in our spacious conference rooms. While your team is busy at team building activities you can plan your next leadership retreat over a game of golf on our professionally maintained chipping and putting greens!" 
    } 
} 
["success"]=> 
int(1) 
} 
+0

你是什么意思的崩溃?是否显示任何错误? – Anton

+0

没有数据传回。我检查了邮差。使用var_dump($ _ POST)我可以看到数据已通过,但没有回显。 @Anton –

+0

在这个脚本中,你如何将数据传递给Android应用程序..? – CoderSam

回答

0

当你使用它$stmt->fetch()返回结果集,而不是一个单独的值。 所以做一些像

$data = $stmt->fetch(); 
$response["resort_desc"][0] = $data["resort_desc"]; 
+0

试过没有变化:( –

+0

你可以删除[0],因为这可能是不需要的,还有设置'$ response [“resort_desc”] = array( );'。 –

+0

完成它:) @Nigel –