
RowResult::getColumnNames 메서드는 RowResult 객체에서 컬럼 이름을 가져올 때 사용됩니다. 이 메서드는 컬럼 이름을 배열로 반환하며, 컬럼 이름을 가져올 때 발생할 수 있는 에러나 예외를 처리할 수 있습니다.
이 메서드를 사용하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$result = $stmt->fetch();
$columnNames = $result->getColumnNames();
foreach ($columnNames as $columnName) {
echo $columnName . "n";
}
위의 예시 코드에서, $result는 RowResult 객체이며, getColumnNames 메서드를 사용하여 컬럼 이름을 가져옵니다. 그리고 foreach 문을 사용하여 컬럼 이름을 출력합니다.
컬럼 이름을 가져올 때 발생할 수 있는 에러나 예외를 처리하는 방법은 다음과 같습니다.
#hostingforum.kr
php
try {
$result = $stmt->fetch();
$columnNames = $result->getColumnNames();
foreach ($columnNames as $columnName) {
echo $columnName . "n";
}
} catch (Exception $e) {
echo "에러 발생 : " . $e->getMessage() . "n";
}
위의 예시 코드에서, try-catch 문을 사용하여 에러나 예외를 처리합니다. 만약에 에러나 예외가 발생하면, catch 블록에서 처리합니다.
2025-07-15 19:18