
MySQLi::autocommit() 사용시 문제가 발생하는 경우는 다음과 같습니다.
- autocommit이 true일 때 commit() 함수를 호출하면 에러가 발생합니다. 이는 autocommit이 true일 때 commit() 함수가 필요하지 않기 때문입니다. autocommit이 true일 때는 각 쿼리가 자동으로 커밋되기 때문입니다.
autocommit이 true일 때 commit() 함수를 호출하는 방법은 다음과 같습니다.
- autocommit을 false로 설정한 후 commit() 함수를 호출합니다.
#hostingforum.kr
php
$conn = mysqli_connect("localhost", "root", "");
mysqli_select_db($conn, "test");
mysqli_autocommit($conn, true);
mysqli_query($conn, "INSERT INTO test_table (col1) VALUES ('value1')");
if (mysqli_autocommit($conn, false)) {
$result = mysqli_commit($conn);
if (!$result) {
echo "Error: " . mysqli_error($conn);
}
} else {
echo "Error: " . mysqli_error($conn);
}
위의 코드에서 autocommit을 false로 설정한 후 commit() 함수를 호출합니다. 이로 인해 autocommit이 false로 설정된 상태에서 commit() 함수를 호출할 수 있습니다.
2025-04-11 23:36