---
name: "mariadb_stmt_execute_direct"
section: "3"
platform: "linux"
package: "mariadb"
version: "13.0.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/mariadb_stmt_execute_direct"
---

# mariadb\_stmt\_execute\_direct(3)

### Name

mariadb\_stmt\_execute\_direct - prepares and executes a prepared statement

### Synopsis

-

  ```
  #include <mysql.h>
  int mariadb_stmt_execute_direct(MYSQL_STMT * stmt,
                                  const char *query,
                                  size_t length);
  ```

### Description

Prepares and executes a statement which was previously allocated by **[mysql\_stmt\_init(3)](/mysql_stmt_init/3.md)**, using the current values of the parameter variables if any parameters exist in the statement.

### Parameters

- •

  `stmt` - A statement handle, which was previously allocated by **[mysql\_stmt\_init(3)](/mysql_stmt_init/3.md)**.

- •

  `query` SQL statement

- •

  `length` Length of SQL statement

### Return value

Returns zero on success, non-zero on failure.

### Notes

- •

  Since the number of parameter of the statement is unknown before execution it is mandatory to set the number of parameters via the **[mysql\_stmt\_attr\_set(3)](/mysql_stmt_attr_set/3.md)** function.

- •

  If the SQL statement is a zero-terminated string, you can also pass `-1` as length.

- •

  The statement handle is intended for one-time execution. Reusing the statement handle might lead to unexpected behavior.

### History

This function was added in Connector/C 3.0 and requires MariaDB 10.2 or later versions.

### See Also

- •

  **[mysql\_stmt\_attr\_set(3)](/mysql_stmt_attr_set/3.md)**

- •

  **[mysql\_stmt\_bind\_param(3)](/mysql_stmt_bind_param/3.md)**

### Example

\`\`\`C static int execute\_direct\_example(MYSQL *mysql) {* *MYSQL\_STMT* stmt= mysql\_stmt\_init(mysql); MYSQL\_BIND bind\[2\]; int intval= 1; int param\_count= 2; char \*strval= “execute\_direct\_example”;

/\* Direct execution without parameters \*/ if (mariadb\_stmt\_execute\_direct(stmt, “CREATE TABLE execute\_direct (a int, b varchar(30))”, -1)) goto error;

memset(&bind, 0, sizeof(MYSQL\_BIND) \* 2); bind\[0\].buffer\_type= MYSQL\_TYPE\_SHORT; bind\[0\].buffer= &intval; bind\[1\].buffer\_type= MYSQL\_TYPE\_STRING; bind\[1\].buffer= strval; bind\[1\].buffer\_length= strlen(strval);

/\* set number of parameters \*/ if (mysql\_stmt\_attr\_set(stmt, STMT\_ATTR\_PREBIND\_PARAMS, &param\_count)) goto error;

/\* bind parameters \*/ if (mysql\_stmt\_bind\_param(stmt, bind)) goto error;

if (mariadb\_stmt\_execute\_direct(stmt, “INSERT INTO execute\_direct VALUES (?,?)”, -1)) goto error;

mysql\_stmt\_close(stmt); return 0; error: printf(“Error: %s”, mysql\_stmt\_error(stmt)); mysql\_stmt\_close(stmt); return 1; }
