# mysql\_sqlstate

## Syntax

```c
const char * mysql_sqlstate(MYSQL * mysql);
```

* `mysql` - a mysql handle, which was previously allocated by [mysql\_init()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_init) or [mysql\_real\_connect()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect).

## Description

Returns a string containing the [SQLSTATE](https://app.gitbook.com/s/SsmexDFPv2xG2OTyO5yV/server-usage/programmatic-compound-statements/programmatic-compound-statements-diagnostics/sqlstate) error code for the most recently invoked function that can succeed or fail. The error code consists of five characters. '00000' means no error. The values are specified by `ANSI SQL` and `ODBC`

{% hint style="info" %}
Please note that not all client library error codes are mapped to `SQLSTATE` errors. Errors which can't be mapped will be returned as value HY000.
{% endhint %}

## See also

* [mysql\_error()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_error)
* [mysql\_errno()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_errno)

{% @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_sqlstate.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.
