개발모음집

php에서 mysql에 현재 시간 넣기 본문

TheRestDevelop

php에서 mysql에 현재 시간 넣기

void 2017. 6. 28. 13:54

안드로이드에서 글쓰기 버튼을 클릭했을 때 현재 시간이 디비에 저장되었으면 좋겠다고 생각


내 디비의 컬럼은 datetime형이었고

검색한 결과  php5.6 이하에서 현재시간을 넣으려면

timestamp형으로 바꿔야한다고 나와있다. 


참고 블로그

그래서 우선 데이터형을 바꾸고 


스택오버플로우에 나온 것 처럼 


$date =date('Y-m-d H:i:s','1299762201428');

를 사용.

하지만 



Warning: date(): It is not safe to rely on the system's timezone settings.
You are *required* to use the date.timezone setting or the date_default_timezone_set() function. 
In case you used any of those methods and you are still getting this warning, 
you most likely misspelled the timezone identifier. 

We selected 'Asia/Seoul' for 'KST/9.0/no DST'


와 같은 에러 발생


참고 블로그 여길 확인해보니

php.ini 파일의 [date]에  date.timezone = Asia/Seoul을 입력해주고

php 파일에서 date 쓰기전에


date_default_timezone_set('Asia/Seoul');

 입력하니 해결