# mysql\_query

## Syntax

```c
int mysql_query(MYSQL * mysql,
                const char * query);
```

* `mysql` - a mysql handle, which was previously allocated by [mysql\_init()](/docs/connectors/mariadb-connector-c/api-functions/mysql_init.md) or [mysql\_real\_connect()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect.md).
* `query` -a null terminated string containing the statement to be performed.

## Description

Performs a statement pointed to by the null terminate string query against the database. Contrary to [mysql\_real\_query()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_query.md), mysql\_query() is not binary safe.

Returns zero on success, non zero on failure

{% hint style="info" %}
For executing multi statements the statements within the null terminated string statements must be separated by a semicolon.

If your statement contains binary data you should use [mysql\_real\_query()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_query.md) or escape your data with [mysql\_hex\_string()](/docs/connectors/mariadb-connector-c/api-functions/mysql_hex_string.md).

To determine if a statement returned a result set use the function [mysql\_num\_fields()](/docs/connectors/mariadb-connector-c/api-functions/mysql_num_fields.md).
{% endhint %}

## See also

* [mysql\_real\_query()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_query.md)
* [mysql\_num\_fields()](/docs/connectors/mariadb-connector-c/api-functions/mysql_num_fields.md)
* [mysql\_hex\_string()](/docs/connectors/mariadb-connector-c/api-functions/mysql_hex_string.md)
* [mysql\_use\_result()](/docs/connectors/mariadb-connector-c/api-functions/mysql_use_result.md)
* [mysql\_store\_result()](/docs/connectors/mariadb-connector-c/api-functions/mysql_store_result.md)

{% @marketo/form formId="4316" %}


---

# Agent Instructions: 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/api-functions/mysql_query.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.
