我创建了一个 Android 应用程序,用于将数据上传到我的网络服务器到 PHP 文件并将数据输出到 .txt
文件。我升级了服务器,现在支持数据库。
如何转换/更新以下 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)
?>
最佳答案
关于php - android上传PHP数据如何与MySQL数据库连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15818878/