-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsg_get.php
More file actions
64 lines (58 loc) · 1.97 KB
/
msg_get.php
File metadata and controls
64 lines (58 loc) · 1.97 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once 'common.inc';
//mb_internal_encoding("UTF-8");
if(isset($_GET['last_id'])){
$last_id = $_GET['last_id'];
if(!is_numeric($last_id)){
header('HTTP/1.0 400 Bad Request');
die('error');
}
}else{
$last_id = 0;
}
//データベースに接続
try {
$pdo = new PDO(CONNECT);
//エラーがあったらcatchに飛ぶ設定
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//$stmt = $pdo->prepare("SELECT * FROM " . TABLE . " Where msg_id > :last_id limit " . MAXMSG);
$stmt = $pdo->prepare("SELECT * FROM " . TABLE . " Where msg_id > :last_id ORDER BY msg_id DESC limit " . MAXMSG);
$stmt->bindValue(':last_id', $last_id, PDO::PARAM_INT);
$stmt->execute();
$msg_array = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e){
var_dump($e->getMessage());
}
$pdo = null;
echo json_encode($msg_array);
//DB接続
//$conn = sqlite_open(DB, 0666, $error) or die ($error);
//
////データの抽出
//if(isset($_GET['last_id'])){
// $sql = "SELECT * FROM " . TABLE . " Where msg_id > {$_GET['last_id']} ORDER BY msg_id DESC limit " . MAXMSG . ";";
// $res = sqlite_unbuffered_query($sql, $conn, SQLITE_ASSOC, $error) or die ($error);
// $i = 0;
// $message = '';
// while ($row = sqlite_fetch_array($res, SQLITE_ASSOC)){
// if($i == 0){
// $message .= '<input type="hidden" id="last_id" value="' . $row["msg_id"] . '" />';
// }
// $message .= '<div>' . $row["name"] . ' : ' . $row["time"] . "<br />" .
// nl2br($row["message"]) . "</div>";
// $msg_id = $row["msg_id"];
// $i++;
// }
//
// //最初にアクセスしかつメッセージがあった場合はid="oldest_id"を加える
// if($_GET['last_id'] == 0 && isset($msg_id)){
// $message .= '<input type="hidden" id="oldest_id" value="' . $msg_id . '" />';
// }
//}
//else{
// $message = "Hey You! What are you doing?";
//}
//
////データを書き出し
//echo $message;
?>