2016-11-23 2 views
1

PHP를 통해 MySQL 데이터베이스를 iPhone 앱에 연결하려고합니다. 나는이 튜토리얼을 따라 가고있다. http://codewithchris.com/iphone-app-connect-to-mysql-database/내 PHP 파일이 반환하지 않는 이유는 무엇입니까?

이것은 내가 처음으로 이런 식으로 일하는 것이므로, 몇 가지 주요 정보를 남겨두면 유감 스럽다. 여기

여기 여기

Here's Bluehost

내 문제 Bluehost를

Here's the plist in Xcode

엑스 코드에서 PLIST이야 내가 Bluehost를

<?php 

// Create connection 
$con=mysqli_connect("localhost","gaethrco_travis","Energy=mc^2","gaethrco_data"); 

// Check connection 
if (mysqli_connect_errno()) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

// This SQL statement selects ALL from the table 'Locations' 
$sql = "SELECT * FROM Locations"; 

// Check if there are results 
if ($result = mysqli_query($con, $sql)) 
{ 
    // If so, then create a results array and a temporary one 
    // to hold the data 
    $resultArray = array(); 
    $tempArray = array(); 

    // Loop through each row in the result set 
    while($row = $result->fetch_object()) 
    { 
     // Add each row into our results array 
     $tempArray = $row; 
     array_push($resultArray, $tempArray); 
    } 

    // Finally, encode the array to JSON and output the results 
    echo json_encode($resultArray); 
} 

// Close connections 
mysqli_close($con); 
?> 

의 데이터베이스에 업로드 PHP 파일입니다 ~이다. 내가 내 웹 사이트 gaethr.com/service.php 에 갈 때 아무 일도 일어나지 않습니다. 튜토리얼에 따르면,이

This is what should happen

내가 몇 가지 중요한 정보를 떠날거야 알려줘 발생한다.

+0

이 질문에 아이폰 OS, 스위프트 3, 엑스 코드 8과 아무 상관을 검증 베타 2. 나는 그 태그를 제거합니다. – Alexander

+0

쿼리가 성공했는지 확인해야합니다. 연결 상태는 양호하지만 쿼리가 실패했을 수 있습니다 (예 :'Locations' 테이블이 존재하지 않습니다) : if ($ result = mysqli_query ($ con, $ sql)) {...} else {echo mysqli_error ($ con); }'* 또는 something * – HPierce

답변

0

먼저 검증 $ 콘

if (!$con) { 
    die("Connection error: " . mysqli_connect_errno()); 
} 

그럼 .. 레코드 그런

if ($result = mysqli_query($con, $sql)) 
{ 
    .... 
} 
else { 
    echo "No results"; 
} 

if(!empty($result) { 
    while ($row = mysqli_fetch_array($result)) { 
... 
+0

그들은 이미 그것을하고 있습니다. 너는 단지 다르게하고있다. –

관련 문제