私は1年間の経験を持つジュニアPHP開発者です。AドメインからBドメインにtxtファイルを送信して実行してください
それが適切でないものがあれば、いくつかの助け
を求めるのは初めてだ、おかげで多くのことを教えてください。
状況:
1.Weは、ドメインAのSQLを更新する2つの異なる場所(ドメインA、ドメインB)
たら、2.を持っているだけでなくJSONタイプでtxtファイルを保存する(JSON。 .TXT)
3.Then 次にSQL
の更新に使用される、ドメインBに4.readをドメインAからこのtxtファイルを "送信" とドメインB上のtxtファイルを復号3210
質問:
状況3でを「送る」は質問が助けする必要があること。
どのような方法をこの状況で使用できますか?ここ
は、コード全体のプロセスである:
Domain A = "c://example"
Domain B = "220.xxx.xx"
testing file = "sending.txt"
ドメインA
<?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 Iは
[{"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);
}
?>
をsvaed TXT
これらの2つのPHPファイルにはどのようなコードを追加する必要がありますか? How to simulate browser form POST method using PHP/cURL
をしかし、私はまだすべてで任意のアイデアを持っていない:
私の上司は私にはこのリンクを与えます。
テストするコードをどこに追加するかわからない。
この質問で利用可能な場合は、ご覧ください。
多くのありがとうございます。