맥OS에서 MAMP를 사용하던 중 갑자기 아파치 서버는 이상 없는데 MySQL 서버가 실행되지 않을 때에는 다음의 파일을 삭제하면 됩니다.
응용 프로그램 > MAMP > db > mysql56 폴더에서 ib_logfileX 파일들을 삭제합니다.
그리고 MAMP를 다시 실행하면, MySQL 서버가 실행되는 것을 확인할 수 있습니다.
맥OS에서 MAMP를 사용하던 중 갑자기 아파치 서버는 이상 없는데 MySQL 서버가 실행되지 않을 때에는 다음의 파일을 삭제하면 됩니다.
응용 프로그램 > MAMP > db > mysql56 폴더에서 ib_logfileX 파일들을 삭제합니다.
그리고 MAMP를 다시 실행하면, MySQL 서버가 실행되는 것을 확인할 수 있습니다.
얼마 전에 자바크크립트에서 여러 개의 문자열 치환하기를 올렸는데, 이번에는 PHP 입니다.
사실 PHP는 str_replace() 함수에서 기본으로 지원하는 기능이라, 팁이라고 하기 민망하긴 하네요 ㅎㅎ
$replace_search = array("\\", "\"", "\'");
$replace_target = array("\\\\", "\\\"", "\\\'");
echo str_replace($replace_search, $replace_target, $row["detail"]);
위의 코드와 같이 str_replace() 함수는 매개변수에 문자열 뿐 아니라 배열도 넣을 수 있습니다.
참고 URL: PHP: str_replace – Manual
디비 조회 시에 최근 한 달, 또는 최근 2주 동안의 데이터가 필요할 때 CURRENT_DATE와 INTERVAL을 사용하면 편하네요.
SELECT * FROM `table` WHERE `date` > CURRENT_DATE - INTERVAL '1' MONTH;
SELECT * FROM `table` WHERE `date` > CURRENT_DATE - INTERVAL '2' WEEK;
SELECT * FROM `table` WHERE `date` > CURRENT_DATE - INTERVAL '10' DAY;
기간도 월, 주, 또는 일 단위 등으로 지정할 수 있습니다.
APMSetup을 사용해서 로컬에 테스트 서버를 만들던 중, PHP 페이지에서 한글을 입력하면 DB에 깨져서 저장되는 문제가 생겼습니다. 이것저것 찾아보면서 서버 및 DB의 인코딩 설정도 UTF8로 바꿔봤지만 문제가 해결되지 않더군요. 그래서 조금 더 검색해 보던중, 다음의 코드를 찾았습니다.
mysql_query("set session character_set_connection=utf8;");
mysql_query("set session character_set_results=utf8;");
mysql_query("set session character_set_client=utf8;");
이 코드를 추가해 주면 한글도 DB에 문제없이 입력이 됩니다.
/**
* uploadok.php
* ------------
* Author: Han Sanghun (http://hangunsworld.com, hanguns@gmail.com)
* Kim Eung (http://eung.co.kr/)
* Release Version: 1.0.0
* Date Started: 2007/04/01
* Last Modified: 2008/01/04
*
* Determines the name of the saved file.
* If "newName" is provided, then uses "newName" as the file's name.
* Otherwise, uses the original filename("Filedata.name") as the filename.
*
* If the original name of the file contains 2-byte characters (e.g. Korean characters), IO error occurs.
* To avoid this, use "newName" parameter defined in Flash, rather than the "Filedata.name".
* It is possible to assigns a new name in PHP code explicitly.
*/
$newName = trim($_REQUEST["newName"]);
if($newName == ""){
// If newName is not defined, uses Filedata.name as the filename.
$newName = $HTTP_POST_FILES['Filedata']['name'];
}
// Creates "images" folder, if not exist.
if(!is_dir("./images")){
mkdir("./images",0777);
}
// Sets the path in which the uploaded image to be stored.
$folderPath = $_SERVER['DOCUMENT_ROOT']."/test/images/";
$newPath = $folderPath.$newName;
// Moves the temporary file.
@move_uploaded_file($HTTP_POST_FILES['Filedata']['tmp_name'], $newPath);
// Returns the saved file path.
echo "/test/images/".$newName;
?>