我是擁有一年經驗的初級php開發人員。將A域的txt文件發送到B域並運行
這是我第一次尋求一些幫助
如果有什麼事,是不是合適,請告訴我,非常感謝。
情況:
1.我們有兩個不同的地方(域A,結構域B)
2,當更新在域A上的SQL,保存在JSON類型txt文件,以及(JSON。 .TXT)
3.Then 「發送」從域A此TXT文件域B
4.read和解碼在域B txt文件,則在更新SQL
使用3210問題:
那「發」在情況3是需要幫助的問題。
在這種情況下可以使用什麼樣的方法?
以下是在代碼的全過程:
Domain A = "c://example"
Domain B = "220.xxx.xx"
testing file = "sending.txt"
DomainA中
<?php
// this code is on Domain A
include_once "lib/database.php";
$pdo = DB_CONNECT();
$file = "sending.txt";
$f = fopen($file, 'w');
// select data from sql, update and put in array, then save it into txt
$sql = "SELECT id,lastupdated FROM customer";
$pdo -> query($sql);
$rs = $pdo -> query($sql);
foreach ($rs as $key => $row) {
$array[$key]=[
"id" => $row["id"],
"lastupdated" => $row["lastupdated"],
];
$sql = "INSERT INTO customer_test (customer_id,lastupdated) VALUES
(".$row["id"].",'".$row["lastupdated"]."')";
$pdo -> query($sql);
}
$array_json = json_encode($array);
fwrite($f, $array_json);
fclose($f);
?>
JSON的TXT我svaed
[{"id":"1","lastupdated":"2017-03-01 13:55:17"},
{"id":"2","lastupdated":"2017-01-08 17:03:39"},
{"id":"3","lastupdated":"2017-02-07 09:34:29"}]
域B
<?php
include_once "lib/database.php";
$pdo = DB_CONNECT();
// get from local txt which has been sent to here From other Domain;
$json_data = file_get_contents('sending.txt');
$array = json_decode($json_data, true);
//then save into same database,but this one is on Domain B.
foreach ($array as $i => $row) {
$id = $array[$i]["id"];
$lastupdated = $array[$i]["lastupdated"];
$sql = "INSERT INTO customer_test (customer_id,lastupdated) VALUES
(".$id.",'".$lastupdated."')";
$pdo -> query($sql);
}
?>
我應該在這兩個php文件中添加什麼代碼?
我的老闆只給這個鏈接對我說: How to simulate browser form POST method using PHP/cURL
但我仍然沒有任何想法。
甚至不知道在哪裏添加我的代碼來測試。
請關注此問題。
非常感謝。