개발모음집

Call to a member function fetch_assoc() on a non-object 에러 본문

TheRestDevelop

Call to a member function fetch_assoc() on a non-object 에러

void 2017. 6. 19. 12:04

$row = $result->fetch_assoc();

를 사용했다.



Call to a member function fetch_assoc() on a non-object

에러가 난다.


내가 실수한 것은 insert문을 보내고 fetch_assoc를 사용해서 에러가 난 것이다.


디비에 insert문을 날리면 0또는 1값이 반환되는데

$result = $db->query($sql);


이 결과값으로 fetch_assoc를 해서 그렇다.


$row = $result->fetch_assoc();

select문이나 데이터의 결과값을 가져올 때 사용하면 오류가 나지않는다.

즉, 쿼리 결과가 없는데 fetch_assoc을 사용하면 오류가 난다.