mariadb\_stmt\_execute\_direct(3) MariaDB Connector/C mariadb\_stmt\_execute\_direct(3)

## [Name](#Name)

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

## [Synopsis](#Synopsis)

```
#include <mysql.h>
int mariadb_stmt_execute_direct(MYSQL_STMT * stmt,


                                const char *query,


                                size_t length);
    
```

## [Description](#Description)

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

## [Parameters](#Parameters)

•

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

•

query SQL statement

•

length Length of SQL statement

## [Return value](#Return_value)

Returns zero on success, non-zero on failure.

## [Notes](#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)**](/man/os/mariadb-12.3/mysql_stmt_attr_set.3) 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](#History)

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

## [See Also](#See_Also)

•

[**mysql\_stmt\_attr\_set(3)**](/man/os/mariadb-12.3/mysql_stmt_attr_set.3)

•

[**mysql\_stmt\_bind\_param(3)**](/man/os/mariadb-12.3/mysql_stmt_bind_param.3)

## [Example](#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; }

Version 3.4

---

Document: mariadb_stmt_execute_direct(3) from mariadb-12.3 12.3.3-r2 (Chainguard OS)
Source: https://github.com/MariaDB/server.git
