개발! 딱 깔끔하고 센스있게!

PHP / 마 이 SQLi: lc time names and DATE FORMAT () 를 마 이 SQLi 조회 로 설정 할 까요? 본문

개발 스크랩 메모/PHP

PHP / 마 이 SQLi: lc time names and DATE FORMAT () 를 마 이 SQLi 조회 로 설정 할 까요?

렉사이 2020. 11. 30. 22:41

나 는 데이터 베 이 스 를 검색 할 때 다음 코드 를 사용한다.

$check_sql = 'SELECT personID, name, DATE_FORMAT(persons.birthdate, "%d de %M, %Y"), birthplace, countryID FROM persons WHERE personID = ?'; if ($stmt->prepare($check_sql)) { $stmt->bind_param('i', $pid); $stmt->bind_result($personDB, $name, $birthdate, $birthplace, $countryID); $stmt->execute(); $stmt->fetch(); } 

보다 시 피 저 는 date format () MySQL 함수 로 "birthdate" 열 에 있 는 날 짜 를 더 호의 적 으로 포맷 합 니 다.

현재, 나 는 스페인어 로 달의 전체 이름 을 표시 하고 싶 어서 검색 에 SET lc time names = 'es' 를 삽입 하고 싶다.

나 어떻게 해 야 돼?저 는 SET lc time names 를 $check sql 변수 에 추가 할 수 있 습 니까?

감사합니다.

대답 하 다.

$mysqli = new mysqli("localhost", "my_user", "my_password", "world"); $mysqli->query("SET lc_time_names = 'es_ES'"); $check_sql = 'SELECT personID, name, DATE_FORMAT(persons.birthdate, "%d de %M, %Y"), birthplace, countryID FROM persons WHERE personID = ?'; if ($stmt = $mysqli->prepare($check_sql)) { $stmt->bind_param('i', $pid); $stmt->bind_result($personDB, $name, $birthdate, $birthplace, $countryID); $stmt->execute(); $stmt->fetch(); } 
Comments