
mysqli::dump_debug_info 함수는 MySQLi 객체의 현재 상태를 덤프하는 함수로, 연결 정보, 옵션, 현재 위치를 반환합니다.
dump_debug_info 함수에서 'last_insert_id' 값이 항상 0으로 나타나는 이유는 MySQLi 객체의 last_insert_id 값을 가져올 때, 자동으로 커밋이 발생하여 이전 INSERT 문에 대한 last_insert_id 값이 초기화되기 때문입니다.
해결 방법은 MySQLi 객체의 autocommit 모드를 OFF로 설정하여 last_insert_id 값을 가져올 때 커밋이 발생하지 않도록 하는 것입니다.
#hostingforum.kr
php
mysqli->autocommit(false);
$result = mysqli->query('INSERT INTO 테이블명 (컬럼명) VALUES (값)');
$last_insert_id = mysqli->insert_id;
mysqli->autocommit(true);
또는 MySQLi 객체를 생성할 때 autocommit 모드를 OFF로 설정할 수 있습니다.
#hostingforum.kr
php
mysqli->autocommit(false);
2025-05-05 23:35