이 블로그 검색

2012년 2월 9일 목요일

bind_result() 에서 out of memory 발생시


에러메시지:
Fatal error: Out of memory (allocated 262144) (tried to allocate 4294967294 bytes) in


bind_result() 에서 out of memory 발생 해결방법

1)php.ini
memory_limit 를 수정한다.
아니면

소스상단에  삽입
ini_set("memory_limit","64M");
                                       (메모리 크기는 각자 적당히)

2)해당 테이블의 컬럼 타입 체크한다.
 content 컬럼이 longtext
그래서 , cast 구문 사용

$stmt = $mysqli->prepare("SELECT title,CAST(content AS char(20000)) from after limit ?");
$stmt->bind_param("i",$limit_no);
$limit_no=10;
$stmt->execute();
echo memory_get_usage()."<br>";
/* 변수를 미리 준비된 문장에 결합, bind variables to prepared statement */
$stmt->bind_result(&$col1, &$col2);


참고)CAST

숫자만 들어있는 컬럼이 있는데, 정렬을 해 보니,
1
11
12
13
2
21

이런씩으로 정렬되는 경우를 본 적이 있을 것이다.
컬럼의 정의가 INT가 아닌 VARCHAR로 되어 있어서 그런 경우가 있다.
이 경우 어떻게 정렬하면 제대로 표현될까....
MySQL에는 (CAST)연산자라는게 있다.

cast type의 종류는
binary
char
signed (부호있는 숫자)
date
datetime
time
unsigned (부호없는 숫자)
등이 있다.

이용 방법은

정렬할 때에는
select * from customers order by cast(customers_id as unsigned);

문자를 숫자로 변환할 때에는
select cast('1' as unsigned) as test
숫자를 문자로 변환할 때에는
select cast(2 as char(1)) as test

댓글 없음:

댓글 쓰기