-
Notifications
You must be signed in to change notification settings - Fork 0
/
teacher_list.php
44 lines (37 loc) · 1.26 KB
/
teacher_list.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
header('Content-Type: text/json; charset=utf-8');
//Ajax通信ではなく、直接URLを叩かれた場合はエラーメッセージを表示
if (
!(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest')
&& (!empty($_SERVER['SCRIPT_FILENAME']) && 'json.php' === basename($_SERVER['SCRIPT_FILENAME']))
)
{
die ('このページは直接ロードしないでください。');
}
try {
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/json; charset=utf-8');
$mysqli = new mysqli("172.18.86.209","labUser","kawa4ken","future_prediction");
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$mysqli->query("SET NAMES 'utf8'");
$query = 'select * from mst_teacher';
$result = $mysqli->query($query);
// 取得したデータを配列に格納
while ($row = $result->fetch_array()){
$users[] = array(
'id'=> $row['id'],
'name' => $row['name'],
);
}
header('Content-Type: application/json');
echo json_encode( $users );
$mysqli->close();
}
catch (PDOException $e)
{
//例外処理
die('Error:' . $e->getMessage());
}