我创建了一个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