dongyizhuang0134 2018-07-20 16:31
浏览 57

将脚本从MySql PDO和INSERT更改为PostGRESql

I followed the steps at this website to create a background service using Android Studio that sends GPS data to a PHP script, that then posts to a MySQL database.

However, I am wanting to post to a Postgres database. I tried several things, but I have not had any success. These are the two PHP scripts from the website tutorial:

config.php script:

<?php
class DB{
private $dbHost="localhost";
private $dbUsername="USER";
private $dbPassword="PASS";
private $dbName="locationdb";

public $db_con;

public function __construct(){
if(!isset($this->db)){
try{
$pdo=new PDO("mysql:host=".$this->dbHost.";dbname=".$this->dbName, $this->dbUsername, $this->dbPassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db_con=$pdo;
}catch(PDOEXCEPTION $e){
die("Failed to connect with mysql :".$e->getMessage());

}
}
}

public function addGPSData($lat, $lon)
{
$sql="INSERT into tblgpslocation(latval, lonval) VALUES (:lat, :lon)";
$stmt=$this->db_con->prepare($sql);
$stmt->bindParam(":lat", $lat);
$stmt->bindParam(":lon", $lon);
$stmt->execute();
$newId=$this->db_con->lastInsertId();
return $newId;
}
}
?>

Script 2:

<?php
include "config.php";

$db= new DB();

if(isset($_POST['gpsdata']) && $_POST['gpsdata']=='true'){
$result=$db->addGPSData($_POST['latitude'], $_POST['longitude']);
if($result>0){
echo "OK";
}else{
echo "error";
}
}
?>

What changes do I need to make in order to make this connect to my postgresql database and post the incoming data?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!