mysql_real_escape_string(3)
π mysql_real_escape_string(3) β MariaDB Connector/C, bestie edition
okay so real quick, this page lives in the MariaDB Connector/C manual, and it's about mysql_real_escape_string β the glow-up your strings need before they go anywhere near an SQL statement. π¦
β¨ NAME β¨
mysql_real_escape_string β escapes a string while taking into account the character set of the connection. periodt.
πΈ SYNOPSIS πΈ
#include <mysql.h>
unsigned long mysql_real_escape_string(MYSQL * mysql,
char * to,
const char * from,
unsigned long);
π DESCRIPTION π
So the whole point of this icon: it builds a legal SQL string you can actually drop into an SQL statement without it all going sideways. You hand it a string, it hands you back an escaped SQL string, and it does that while respecting the current character set of the connection. no cap, that charset awareness is literally the whole flex here.
π PARAMETER π
the cast of characters, bestie:
mysqlβ a mysql handle. it's gotta be one that was previously allocated bymysql_init(3)and then connected bymysql_real_connect(3). no handshake, no service. πtoβ the buffer where the encoded string goes. and listen, the size of this buffer must belength * 2 + 1bytes. why? because in the worst case every single character of thefromstring needs to be escaped. plus a trailing0character gets appended. so yes, that+ 1is doing real work, do not skip it πfromβ the string thatmysql_real_escape_string()is gonna encode.longβ the length of thefromstring.
π«Ά RETURN VALUE π«Ά
Returns the length of the encoded (to) string. that's it, that's the gift.
π SEE ALSO π
mysql_escape_string(3)mysql_hex_string(3)
β cute sign-off β
and that's the whole page, bestie π this one's from Version 3.4 of the MariaDB Connector/C manual β go forth and escape responsibly, mwah πβ¨
π¦ where this page comes from
- alpine 3.22: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.23: mariadb-doc 11.4.13-r0 Β· GPL-2.0-or-later
- alpine 3.24: mariadb-doc 11.8.9-r0 Β· GPL-2.0-only
- arch rolling: mariadb 13.0.2-2 Β· GPL-2.0-only
- arch rolling: mariadb-lts 12.3.3-2 Β· GPL-2.0-only
- centos-stream 10: mariadb-connector-c-doc 3.4.4-2.el10 Β· LGPL-2.1-or-later
- debian trixie: libmariadb-dev 1:11.8.6-0+deb13u1 Β· GPL-2.0-only
- fedora 43: mariadb-connector-c-doc 3.4.5-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 43: mariadb-connector-c-doc 3.4.9-2.fc43 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- fedora 44: mariadb-connector-c-doc 3.4.8-3.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01
- fedora 44: mariadb-connector-c-doc 3.4.9-2.fc44 Β· LGPL-2.1-or-later AND PHP-3.0 AND PHP-3.01 AND LicenseRef-Fedora-Public-Domain
- nixpkgs unstable: mariadb-server 11.8.8
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- opensuse-leap 16.0: libmariadb-devel 3.4.9-160000.1.1 Β· LGPL-2.1-or-later
- ubuntu questing: libmariadb-dev 1:11.8.3-1build1
- ubuntu resolute: libmariadb-dev 1:11.8.6-5 Β· GPL-2.0-only
- ubuntu resolute: libmariadb-dev 1:11.8.6-5ubuntu0.1 Β· GPL-2.0-only
- ubuntu stonking: libmariadb-dev 1:11.8.9+ds-4ubuntu2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms