For the complete documentation index, see llms.txt. This page is also available as Markdown.

MariaDB Connector/C API Prepared Statement Functions

Explore API functions for prepared statements in Connector/C. This section provides detailed documentation on using prepared statements for efficient and secure query execution in C applications.

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

Prepares and executes a statement in a single call using a pre-allocated MYSQL_STMT handle, available in Connector/C 3.0 and later.

Returns an array of MYSQL_FIELD descriptors for each result set column of a prepared statement, added in MariaDB Connector/C 3.1.0.

Returns the number of rows affected by the last INSERT, UPDATE, DELETE, or REPLACE prepared statement, or -1 if the statement failed.

Retrieves the current value of a prepared statement attribute, such as cursor type, prefetch row count, or max-length update behavior.

Configures a prepared statement attribute on a Connector/C statement handle; supported attributes include cursor type, prefetch rows, and bulk-insert array size.

Binds an array of MYSQL_BIND variables to the parameter markers in a prepared statement before it is executed via mysql_stmt_execute.

Maps result-set columns to application variables via an array of MYSQL_BIND structures, enabling mysql_stmt_fetch to populate those variables.

Deallocates a prepared statement handle and cancels any pending results, freeing server and client resources associated with the statement.

Positions the row cursor to an arbitrary offset in a buffered prepared statement result set previously stored with mysql_stmt_store_result.

Returns the numeric error code for the most recently invoked Connector/C prepared statement function, or zero if no error occurred.

Retrieves the human-readable error message from the last Connector/C prepared statement call, complementing the numeric code from mysql_stmt_errno.

Runs a prepared statement previously set up with mysql_stmt_prepare, substituting bound parameter values and returning zero on success.

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.

Fetches part of a single column value from the current prepared statement row, allowing large data to be read incrementally via an offset.

Reports how many fields a prepared statement result set contains; it returns zero for INSERT, UPDATE, DELETE, and REPLACE statements.

Frees client-side result memory for a Connector/C prepared statement, complementing mysql_stmt_store_result to manage buffer lifecycle.

Allocates and initializes a MYSQL_STMT prepared statement handle for a Connector/C connection, returning NULL if memory allocation fails.

Returns the AUTO_INCREMENT value generated by the most recent prepared INSERT or UPDATE statement, or zero if no auto-increment column was affected.

Indicates if one or more results from a previously executed prepared statement are available.

Advances to the next result set when a prepared statement returns multiple results, enabling traversal of multi-statement query output.

Returns the total row count of a buffered prepared statement result set; it requires mysql_stmt_store_result to have been called first.

Reports how many placeholder parameters a prepared statement contains, indicating the size of the MYSQL_BIND array required for binding.

Retrieves parameter metadata for a prepared statement handle, returning a MYSQL_RES pointer that describes the bound parameters.

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.

Resets a prepared statement on both client and server to its post-prepare state, clearing unbuffered results and errors while preserving bindings.

Retrieves result-set metadata from a Connector/C prepared statement; the returned MYSQL_RES contains field information but no row data.

Positions the row cursor to an arbitrary row in a buffered prepared statement result set, returning the previous cursor offset for later restoration.

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.

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.

Returns the five-character SQLSTATE error code for the most recently invoked prepared statement function, with '00000' indicating no error occurred.

Buffers the complete result set of a prepared SELECT, SHOW, DESCRIBE, or EXPLAIN statement on the client, enabling random access and row count queries.

Reports how many warnings the most recent Connector/C prepared statement raised; added in Connector/C 3.0. Use SHOW WARNINGS to retrieve messages.

Data structures and type definitions used by the prepared-statement API, including MYSQL_BIND and MYSQL_STMT.

Worked prepared-statement examples, including bulk inserts with column-wise and row-wise parameter binding.

This page is: Copyright © 2026 MariaDB. All rights reserved.

Last updated

Was this helpful?