What is the purpose of odbc_result_all() in PHP and how can its output be formatted?
The purpose of odbc_result_all() in PHP is to fetch all rows from a result set as an associative array. The output can be formatted using PHP functions like json_encode() to convert the array into a JSON string or foreach loop to iterate over the array and display the data in a desired format.
// Connect to the database
$conn = odbc_connect($dsn, $user, $password);
// Execute a query
$query = "SELECT * FROM table";
$result = odbc_exec($conn, $query);
// Fetch all rows as an associative array
$rows = odbc_result_all($result);
// Format the output as JSON
echo json_encode($rows);