[php-ajax] 빈번한 MySQL 업로드 오류 (x그누보드)
본문
[php] 빈번한 MySQL 업로드 오류 (x그누보드)
안녕하세요.
php mysql을 이용하여 채팅기능을 만들었는데, (소스는 자체제작입니다.)
Ajax로 update 때려서 DB(Mysql)에 업로드하고 새로고침하는 방식입니다.
그런데, 서버와 클라이언트 테스트하는데 3번~5번 넘어가면 업로드가 안되고(새로고침해도 아무것도 안뜸)
잠시후 MySQL 들어가면 전부 사라집니다. 허ㅓㅎ;;;;
상당히 안정성이 취약한데,
이유가 무엇이며, 소스의 개선방향을 아신다면 큰 가르침 부탁드립니다... \(ㅠ_ㅠ)/
자바스크립트
<script type="text/javascript">
function chatsubmit(){
$("#inst-card-d").addClass('loading');
if($("#form_ch_content").val()){
$.ajax({
type: "POST",
url: "./nhchat_update.php",
data: {
"wr_id" : $("#form_wr_id").val(),
"bo_table" : $("#form_bo_table").val(),
"ch_from" : $("#form_ch_from").val(),
"ch_to" : $("#form_ch_to").val(),
"ch_content" : $("#form_ch_content").val()
},
cache: true,
async: true,
success: function(data) {
location.reload();
}
});
}else{
alert('내용이 없습니다.');
$("#inst-card-d").removeClass('loading');
}
}
</script>
nhchat_update.php
<?
include_once('./_common.php');
$write_table = 'nh_chat';
$wr_id = trim($_POST['wr_id']);
$bo_table = trim($_POST['bo_table']);
$ch_from = trim($_POST['ch_from']);
$ch_to = trim($_POST['ch_to']);
$ch_content = trim($_POST['ch_content']);
$ch_id_next = nh_chat_get_next_num();
if(!$ch_content){
alert('내용이 없습니다.');
}
$sql = " insert into $write_table
set ch_id = '$ch_id_next',
wr_id = '$wr_id',
ch_from = '$ch_from',
ch_to = '$ch_to',
ch_content = '$ch_content',
bo_table = '$bo_table',
ch_datetime = '".G5_TIME_YMDHIS."' ";
sql_query($sql);
$wi_id = sql_insert_id();
// 부모 아이디에 UPDATE
sql_query(" update $write_table set wr_parent = '$wi_id' where wi_id = '$wi_id' ");
?>
!-->!-->
답변 5
sql_query() 실행전에 쿼리가 어떻게 만들어지는지 확인 한번해보세요.
print_r2($sql);
sql_query($sql);
저도 잘은 모르지만 채팅 자체가 ajax로 하기에는 상당히 불안정 하지 않나요 보통 node.js 이용 해서 소켓 통신을 하는것으로 알고 있는데요
소스의 마지막 쿼리중
where wi_id =
을 where wr_id =
로 바꿔보시죠
지금이라도 늦지 않았습니다. 채팅을 만들어보고 싶으시다면, nodejs 를 쓰세요.
간단한 채팅은 어렵지 않습니다.
지금 nodejs 를 시작한다면, 나중에 지금의 결정을 매우 잘한일이라고 생각할거에요.
nodejs 설치가 어렵다면, nodejs 호스팅을 알아보셔도 됩니다.
저도 ajax로 채팅 구현한적있는데여 머랄까...
상당히 불안전한 면이 있긴합니다.
지금생각해도 구현이 안되는건 안될거같진않은데
위와같은 문제가 생깁니다. 안정성에서 문제가 되는거같아여
소켓통신이나 node.js 아니면 다른 채팅 관련 프로그램을 참고하시는게
좋을거같습니다.
답변을 작성하시기 전에 로그인 해주세요.