> 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/api-prepared-statement-functions.md).

# MariaDB Connector/C API Prepared Statement Functions

The MariaDB Connector/C prepared-statement API provides functions for allocating statement handles, binding input parameters and result columns, executing prepared statements, and navigating, buffering, and inspecting their result sets.

## Function Overview

| Function                                                                                                                                | Description                                                                                                                                                       |
| --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`mariadb_stmt_execute_direct()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mariadb_stmt_execute_direct.md) | Prepares and executes a statement in a single call using a pre-allocated MYSQL\_STMT handle, available in Connector/C 3.0 with MariaDB 10.2 or later.             |
| [`mariadb_stmt_fetch_fields()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mariadb_stmt_fetch_fields.md)     | Returns an array of MYSQL\_FIELD descriptors for each result set column of a prepared statement, added in MariaDB Connector/C 3.1.0.                              |
| [`mysql_stmt_affected_rows()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_affected_rows.md)       | Returns the number of rows affected by the last INSERT, UPDATE, DELETE, or REPLACE prepared statement, or -1 if the statement failed.                             |
| [`mysql_stmt_attr_get()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_attr_get.md)                 | Retrieves the current value of a prepared statement attribute, such as cursor type, prefetch row count, or max-length update behavior.                            |
| [`mysql_stmt_attr_set()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_attr_set.md)                 | Configures a prepared statement attribute on a Connector/C statement handle; supported attributes include cursor type, prefetch rows, and bulk-insert array size. |
| [`mysql_stmt_bind_param()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_bind_param.md)             | Binds an array of MYSQL\_BIND variables to the parameter markers in a prepared statement before it is executed via mysql\_stmt\_execute.                          |
| [`mysql_stmt_bind_result()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_bind_result.md)           | Maps result-set columns to application variables via an array of MYSQL\_BIND structures, enabling mysql\_stmt\_fetch to populate those variables.                 |
| [`mysql_stmt_close()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_close.md)                       | Deallocates a prepared statement handle and cancels any pending results, freeing server and client resources associated with the statement.                       |
| [`mysql_stmt_data_seek()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_data_seek.md)               | Positions the row cursor to an arbitrary offset in a buffered prepared statement result set previously stored with mysql\_stmt\_store\_result.                    |
| [`mysql_stmt_errno()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_errno.md)                       | Returns the numeric error code for the most recently invoked Connector/C prepared statement function, or zero if no error occurred.                               |
| [`mysql_stmt_error()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_error.md)                       | Retrieves the human-readable error message from the last Connector/C prepared statement call, complementing the numeric code from mysql\_stmt\_errno.             |
| [`mysql_stmt_execute()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_execute.md)                   | Runs a prepared statement previously set up with mysql\_stmt\_prepare, substituting bound parameter values and returning zero on success.                         |
| [`mysql_stmt_fetch()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_fetch.md)                       | Retrieves the next row from a prepared statement result set into the buffers bound by mysql\_stmt\_bind\_result, returning MYSQL\_NO\_DATA at end of set.         |
| [`mysql_stmt_fetch_column()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_fetch_column.md)         | Fetches part of a single column value from the current prepared statement row, allowing large data to be read incrementally via an offset.                        |
| [`mysql_stmt_field_count()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_field_count.md)           | Reports how many fields a prepared statement result set contains; it returns zero for INSERT, UPDATE, DELETE, and REPLACE statements.                             |
| [`mysql_stmt_free_result()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_free_result.md)           | Frees client-side result memory for a Connector/C prepared statement, complementing mysql\_stmt\_store\_result to manage buffer lifecycle.                        |
| [`mysql_stmt_init()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_init.md)                         | Allocates and initializes a MYSQL\_STMT prepared statement handle for a Connector/C connection, returning NULL if memory allocation fails.                        |
| [`mysql_stmt_insert_id()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_insert_id.md)               | Returns the AUTO\_INCREMENT value generated by the most recent prepared INSERT or UPDATE statement, or zero if no auto-increment column was affected.             |
| [`mysql_stmt_more_results()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_more_results.md)         | Indicates if one or more results from a previously executed prepared statement are available.                                                                     |
| [`mysql_stmt_next_result()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_next_result.md)           | Advances to the next result set when a prepared statement returns multiple results, enabling traversal of multi-statement query output.                           |
| [`mysql_stmt_num_rows()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_num_rows.md)                 | Returns the total row count of a buffered prepared statement result set; it requires mysql\_stmt\_store\_result to have been called first.                        |
| [`mysql_stmt_param_count()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_param_count.md)           | Reports how many placeholder parameters a prepared statement contains, indicating the size of the MYSQL\_BIND array required for binding.                         |
| [`mysql_stmt_param_metadata()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_param_metadata.md)     | Retrieves parameter metadata for a prepared statement handle, returning a MYSQL\_RES pointer that describes the bound parameters.                                 |
| [`mysql_stmt_prepare()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_prepare.md)                   | Parses and prepares a SQL statement on a Connector/C MYSQL\_STMT handle; parameter markers must be bound with mysql\_stmt\_bind\_param before execution.          |
| [`mysql_stmt_reset()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_reset.md)                       | Resets a prepared statement on both client and server to its post-prepare state, clearing unbuffered results and errors while preserving bindings.                |
| [`mysql_stmt_result_metadata()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_result_metadata.md)   | Retrieves result-set metadata from a Connector/C prepared statement; the returned MYSQL\_RES contains field information but no row data.                          |
| [`mysql_stmt_row_seek()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_row_seek.md)                 | Positions the row cursor to an arbitrary row in a buffered prepared statement result set, returning the previous cursor offset for later restoration.             |
| [`mysql_stmt_row_tell()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_row_tell.md)                 | Returns the current row cursor offset of a buffered prepared statement result set, which can be passed to mysql\_stmt\_row\_seek to restore the position.         |
| [`mysql_stmt_send_long_data()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_send_long_data.md)     | Sends a parameter value in chunks to the server, enabling large TEXT or BLOB data that exceeds max\_allowed\_packet to be streamed in multiple calls.             |
| [`mysql_stmt_sqlstate()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_sqlstate.md)                 | Returns the five-character SQLSTATE error code for the most recently invoked prepared statement function, with '00000' indicating no error occurred.              |
| [`mysql_stmt_store_result()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_store_result.md)         | Buffers the complete result set of a prepared SELECT, SHOW, DESCRIBE, or EXPLAIN statement on the client, enabling random access and row count queries.           |
| [`mysql_stmt_warning_count()`](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/mysql_stmt_warning_count.md)       | Reports how many warnings the most recent Connector/C prepared statement raised; added in Connector/C 3.0. Use SHOW WARNINGS to retrieve messages.                |

## Related

{% columns %}
{% column %}
{% content-ref url="/pages/AFaQO1QDG5qtyeN5EXcG" %}
[Connector C Data Structures and Definitions](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/connector-c-data-structures-and-definitions.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
Data structures and type definitions used by the prepared-statement API, including MYSQL\_BIND and MYSQL\_STMT.
{% endcolumn %}
{% endcolumns %}

{% columns %}
{% column %}
{% content-ref url="/pages/lgFEsIlmtADHcuE4MdFw" %}
[Prepared Statement Examples](/docs/connectors/mariadb-connector-c/api-prepared-statement-functions/prepared-statement-examples.md)
{% endcontent-ref %}
{% endcolumn %}

{% column %}
Worked prepared-statement examples, including bulk inserts with column-wise and row-wise parameter binding.
{% endcolumn %}
{% endcolumns %}
