> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/connectors/mariadb-connector-c/mariadb-binlogreplication-api-reference/replication-api-function-reference/mariadb_rpl_fetch.md).

# mariadb\_rpl\_fetch()

Fetches the next event from an open binary log stream.

### Syntax

```sql
#include <mariadb_rpl.h>

MARIADB_RPL_EVENT *mariadb_rpl_fetch(MARIADB_RPL *rpl,
                                      MARIADB_RPL_EVENT *event);
```

### Parameters

| Parameter | Description                                                                                                                                                                                                                                                                                                                                                                         |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `rpl`     | An open replication handle initialized by [mariadb\_rpl\_init()](/docs/connectors/mariadb-connector-c/mariadb-binlogreplication-api-reference/replication-api-function-reference/mariadb_rpl_init.md) and connected by [mariadb\_rpl\_open()](/docs/connectors/mariadb-connector-c/mariadb-binlogreplication-api-reference/replication-api-function-reference/mariadb_rpl_open.md). |
| `event`   | An event returned by a previous call to `mariadb_rpl_fetch`. If this parameter is set to `NULL`, the function allocates new memory for the event. If a non‑NULL value is provided, the existing event structure is overwritten with the new data.                                                                                                                                   |

### Return Value

Returns a pointer to a [`MARIADB_RPL_EVENT`](http://replication-api-data-structures.md/#mariadb_rpl_event) structure containing the next event on success, or `NULL` when the EOF packet is received or an error occurs.

### Note

Event memory must be freed by calling `mariadb_free_rpl_event()` when the event is no longer needed.

### History

Added in [MariaDB Connector/C 3.1.0](/docs/release-notes/connectors/c/3.1/3.1.0.md).

### See also

* [`mariadb_free_rpl_event()`](/docs/connectors/mariadb-connector-c/mariadb-binlogreplication-api-reference/replication-api-function-reference/mariadb_free_rpl_event.md)&#x20;
* [`mariadb_rpl_extract_rows()`](/docs/connectors/mariadb-connector-c/mariadb-binlogreplication-api-reference/replication-api-function-reference/mariadb_rpl_extract_rows.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/connectors/mariadb-connector-c/mariadb-binlogreplication-api-reference/replication-api-function-reference/mariadb_rpl_fetch.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
