1
我試圖通過PHP連接MySQL數據庫的iPhone應用程序。我下面這個教程http://codewithchris.com/iphone-app-connect-to-mysql-database/爲什麼我的PHP文件返回什麼?
這是我第一次做這樣的事情,所以我很抱歉,如果我離開了一些關鍵的信息。
下面是我上傳到數據庫上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文件下面是在Xcode中plist中
這裏的BlueHost的
我的問題是當我去我的網站gaethr.com/service.php 沒有任何反應。按照教程,這應該發生
讓我知道如果我離開了一些關鍵的信息。
這個問題無關與iOS,斯威夫特3或8的Xcode,測試版2.我正在刪除這些標籤。 – Alexander
您應該檢查查詢是否成功 - 可能連接良好,但查詢失敗(例如,Locations表不存在):if($ result = mysqli_query($ con,$ sql)) {...} else {echo mysqli_error($ con); }'*或其他* – HPierce