我創建了一個android應用程序,用於將數據上傳到我的網絡服務器,並將數據輸出到.txt
文件。我升級了我的服務器,現在我支持數據庫。如何連接android上傳PHP數據與MySQL數據庫?
如何轉換/更新下面的PHP代碼與MySQL數據庫連接? Android中端使用HTTP POST到URL的mysite/location.php 我想添加記錄經緯度到我的數據庫... MySQL查詢...需要的代碼示例...
<?php
$lat = $_POST["lat"]; // Declares the upload data from client as a variable
$lon = $_POST["lon"];
$textfile = "location.txt"; // Declares the name and location of the .txt file
$fileLocation = "$textfile";
$fh = fopen($fileLocation, 'w ') or die("Something went wrong!"); // Opens up the .txt file for writing and replaces any previous content
$stringToWrite = " $lat\n $lon\n "; // Write location
fwrite($fh, $stringToWrite); // Writes it to the .txt file
fclose($fh);
//header("Location: index.html"); // Return to frontend (index.html)
?>
第1步:[Learn PDO](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/)。 – tadman 2013-04-04 18:30:52
看我的編輯。它給出了一個示例代碼的鏈接。請投票或標記爲答案,如果你覺得有幫助。謝謝。 – Jordan 2013-04-04 18:54:35