# mysql\_hex\_string

## Syntax

```c
unsigned long mysql_hex_string(char * to,
                               const char * from,
                               unsigned long len);
```

* `to` - result buffer
* `from` - the string which will be encoded
* `len` - length of the string (from)

## Description

This function is used to create a hexadecimal string which can be used in SQL statements. e.g. `INSERT INTO my_blob VALUES(X'A0E1CD')`.

Returns the length of the encoded string without the trailing null character.

{% hint style="info" %}
The size of the buffer for the encoded string must be 2 \* length + 1.

The encoded string does not contain a leading X'.
{% endhint %}

## See also

* [mysql\_real\_escape\_string()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_escape_string.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_hex_string.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.
