> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_sqlstate.md).

# mysql\_sqlstate

## Syntax

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

## Parameter

* `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).

## Description

Returns a string containing the [SQLSTATE](/docs/server/reference/sql-statements/programmatic-compound-statements/programmatic-compound-statements-diagnostics/sqlstate.md) 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()](/docs/connectors/mariadb-connector-c/api-functions/mysql_error.md)
* [mysql\_errno()](/docs/connectors/mariadb-connector-c/api-functions/mysql_errno.md)

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