|
日時: 2015/10/12 13:36
名前: lightbox
|
拡張子:
<?php
header( "Content-Type: application/json; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
header( "Access-Control-Allow-Origin: *" );
$server = 'localhost';
$db_name = 'lightbox';
$user = 'root';
$password = 'パスワード';
$json_type = JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
$db_data_type = MYSQLI_ASSOC;
// 接続
$connect = @ new mysqli($server, $user, $password, $db_name);
if ($connect->connect_error) {
die('Connect Error (' . $connect->connect_errno . ') '
. $connect->connect_error);
}
$connect->set_charset("utf8");
// クエリ
$_GET["scode"] = str_replace("'","''",$_GET["scode"]);
$result = $connect->query("select * from 社員マスタ where 社員コード = '{$_GET["scode"]}'");
if ( !$result ) {
die('クエリーに誤りがあります : ' . $connect->error );
}
// 内容を書き込むファイルの準備
$log_file = "rowdata_002.json";
file_put_contents( $log_file,"" );
$check = false;
while ($row = $result->fetch_array($db_data_type)) {
$check = true;
print json_encode($row,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
print "\n";
// ファイルに追加出力
file_put_contents( $log_file, print_r(json_encode($row,$json_type)."\n",true), FILE_APPEND );
}
// 開放
$result->close();
// 接続解除
$connect->close();
if (!$check) {
print <<< ERROR
{
"社員コード": "{$_GET["scode"]}",
"氏名": "ERROR",
"フリガナ": null,
"所属": null,
"性別": null,
"作成日": null,
"更新日": null,
"給与": null,
"手当": null,
"管理者": null
}
ERROR;
}
?>
|