Add: sql - login, history_record
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$db_host = "localhost";
|
||||
$db_user = "jisangs";
|
||||
$db_passwd = "Fr12nds95";
|
||||
$db_name = "jisangs";
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "send_error_code.php";
|
||||
|
||||
include "connect_db.php";
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$query = "SELECT * FROM afterschool_activated_stage";
|
||||
$result = mysqli_query($db_conn, $query);
|
||||
|
||||
$return_array = array();
|
||||
|
||||
if ( $result ) {
|
||||
// echo "조회된 행의 수 : ".mysqli_num_rows($result)."<br />";
|
||||
|
||||
if($result) {
|
||||
$rows = array();
|
||||
while($row = mysqli_fetch_assoc($result)) {
|
||||
// $row_array['Language'] = $row['Language'];
|
||||
$row_array['StageName'] = $row['StageName'];
|
||||
$row_array['Activated'] = $row['Activated'];
|
||||
array_push($return_array, $row_array);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
send_error_code("Error : ".mysqli_error($db_conn));
|
||||
}
|
||||
|
||||
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
// 결과 해제
|
||||
mysqli_free_result($result);
|
||||
|
||||
$db_conn->close();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
$hasServiceDBSetting = file_exists("./service_db_setting.php");
|
||||
|
||||
if($hasServiceDBSetting == true) {
|
||||
include("./service_db_setting.php");
|
||||
} else {
|
||||
$db_host = "localhost";
|
||||
$db_user = "afterschool";
|
||||
$db_passwd = "sEobMPuJ2A8KTfwU";
|
||||
$db_name = "jisangs";
|
||||
}
|
||||
|
||||
$db_conn = new mysqli($db_host, $db_user, $db_passwd, $db_name);
|
||||
|
||||
if ($db_conn->connect_error) {
|
||||
send_error_code("Connection failed: ".$db_conn->connect_error);
|
||||
exit;
|
||||
}
|
||||
|
||||
$query = "USE jisangs";
|
||||
$result = mysqli_query($db_conn, $query);
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
function send_error_code($error_code) {
|
||||
$returnValue = array(
|
||||
'error' => $error_code
|
||||
);
|
||||
echo json_encode($returnValue, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "./../send_error_code.php";
|
||||
|
||||
$user_id = $_POST["UserID"];
|
||||
$app_name = $_POST["AppName"];
|
||||
|
||||
include "./../connect_db.php";
|
||||
|
||||
|
||||
// my ranking
|
||||
$query = "
|
||||
SELECT DATE(DateTime) AS Date, MAX(Score) AS HighScore, AppName AS AppName
|
||||
FROM moty_record D
|
||||
WHERE UserID = ?
|
||||
GROUP BY DATE(DateTime)
|
||||
ORDER BY DateTime ASC
|
||||
LIMIT 7;
|
||||
";
|
||||
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('s', $user_id);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->bind_result($date, $score, $app_name);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['Date'] = $date;
|
||||
$best_record['HighScore'] = $score;
|
||||
$best_record['AppName'] = $app_name;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
array_push($return_array, $best_record);
|
||||
}
|
||||
$return_array['history'] = $bestRecordArray;
|
||||
|
||||
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$db_conn->close();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "send_error_code.php";
|
||||
|
||||
$user_id = $_POST["UserID"];
|
||||
$language = $_POST["language"];
|
||||
$stageName = $_POST["stageName"];
|
||||
$record = $_POST["Record"];
|
||||
$stage_name = $language."_".$stageName;
|
||||
// $user_id = $_GET["UserID"];
|
||||
// $language = $_GET["language"];
|
||||
// $stageName = $_GET["stageName"];
|
||||
// $best_record = $_GET["BestRecord"];
|
||||
// $typing_stage = $language."_".$stageName;
|
||||
|
||||
// echo $user_id."\n";
|
||||
// echo $typingStage."\n";
|
||||
|
||||
include "connect_db.php";
|
||||
|
||||
$query = "
|
||||
INSERT INTO afterschool_record (UserID, Record, RecordDateTime, StageName)
|
||||
VALUES (?, ?, NOW(), ?);
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ids', $user_id, $record, $stage_name);
|
||||
$stmt->execute();
|
||||
|
||||
$db_conn->close();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "send_error_code.php";
|
||||
|
||||
$user_id = $_POST["UserID"];
|
||||
$language = $_POST["language"];
|
||||
$stageNameDetail = $_POST["stageName"];
|
||||
$stageName = $language."_".$stageNameDetail;
|
||||
|
||||
include "connect_db.php";
|
||||
|
||||
|
||||
// my ranking
|
||||
$query = "
|
||||
SELECT DATE(RecordDateTime) AS Date, MAX(Record) AS BestRecord, StageName AS StageName
|
||||
FROM afterschool_record D
|
||||
WHERE UserID = ?
|
||||
GROUP BY DATE(RecordDateTime)
|
||||
ORDER BY RecordDateTime DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('s', $user_id);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->bind_result($date, $record, $stage_name);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['Date'] = $date;
|
||||
$best_record['BestRecord'] = $record;
|
||||
$best_record['StageName'] = $stage_name;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
array_push($return_array, $best_record);
|
||||
}
|
||||
$return_array['myRanking'] = $bestRecordArray;
|
||||
|
||||
|
||||
// ranking hour
|
||||
$query = "
|
||||
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
|
||||
FROM afterschool_record D, afterschool_user U
|
||||
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND HOUR(D.RecordDateTime) = HOUR(NOW()) AND StageName = ?
|
||||
GROUP BY D.userID
|
||||
ORDER BY max(D.Record) DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('s', $stageName);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->bind_result($userID, $name, $record);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['UserID'] = $userID;
|
||||
$best_record['Name'] = $name;
|
||||
$best_record['BestRecord'] = $record;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
// array_push($return_array, $best_record);
|
||||
}
|
||||
$return_array['rankingHour'] = $bestRecordArray;
|
||||
|
||||
|
||||
// ranking day
|
||||
$query = "
|
||||
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
|
||||
FROM afterschool_record D, afterschool_user U
|
||||
WHERE D.userID = U.userID AND DATE(D.RecordDateTime) = DATE(NOW()) AND StageName = ?
|
||||
GROUP BY D.userID
|
||||
ORDER BY max(D.Record) DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('s', $stageName);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->bind_result($userID, $name, $record);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['UserID'] = $userID;
|
||||
$best_record['Name'] = $name;
|
||||
$best_record['BestRecord'] = $record;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
// array_push($return_array, $best_record);
|
||||
}
|
||||
$return_array['rankingDay'] = $bestRecordArray;
|
||||
|
||||
|
||||
// ranking month
|
||||
$query = "
|
||||
SELECT D.userID As UserID, U.Name AS Name, MAX(D.record) AS BestRecord
|
||||
FROM afterschool_record D, afterschool_user U
|
||||
WHERE D.userID = U.userID AND MONTH(D.RecordDateTime) = MONTH(NOW()) AND StageName = ?
|
||||
GROUP BY D.userID
|
||||
ORDER BY max(D.Record) DESC;
|
||||
";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('s', $stageName);
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->bind_result($userID, $name, $record);
|
||||
|
||||
$bestRecordArray = array();
|
||||
while($stmt->fetch()) {
|
||||
$best_record['UserID'] = $userID;
|
||||
$best_record['Name'] = $name;
|
||||
$best_record['BestRecord'] = $record;
|
||||
array_push($bestRecordArray, $best_record);
|
||||
// array_push($return_array, $best_record);
|
||||
}
|
||||
$return_array['rankingMonth'] = $bestRecordArray;
|
||||
|
||||
echo json_encode($return_array, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
|
||||
$db_conn->close();
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
include "./../send_error_code.php";
|
||||
|
||||
$name = $_POST["name"];
|
||||
$enterCode = $_POST["enter_code"];
|
||||
/*
|
||||
if(!is_numeric($enterCode)) {
|
||||
send_error_code('생년월일이 숫자가 아닙니다. : '.$enterCode);
|
||||
exit;
|
||||
} else if(strlen($enterCode) != 6) {
|
||||
send_error_code('6자리 숫자값을 정확히 입력하세요 : YYMMDD (예 : 120131) : '.$enterCode);
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
|
||||
include "./../connect_db.php";
|
||||
|
||||
$return_array = array();
|
||||
|
||||
$query = "SELECT UserID FROM moty_user WHERE Name=? AND enterCode=?";
|
||||
$stmt = $db_conn->prepare($query);
|
||||
$stmt->bind_param('ss', $name, $enterCode);
|
||||
$stmt->execute();
|
||||
$stmt->bind_result($user_id);
|
||||
// while($stmt->fetch())
|
||||
$stmt->fetch();
|
||||
|
||||
$jsonUserData["UserID"] = $user_id;
|
||||
echo json_encode($jsonUserData, JSON_UNESCAPED_UNICODE);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user