mysql_set_character_set(3)

πŸ“¦
version 13.0.2 Β· 5 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, debian trixie, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’… mysql_set_character_set β€” bestie, let's set ur default charset

okay so this one is from the MariaDB Connector/C manual, and it's literally the glow-up your connection needs. it's giving "pick a character set and commit to it" energy. ✨


🌸 NAME 🌸

mysql_set_character_set β€” sets the default character set for the connection, no cap πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <mysql.h>

int mysql_set_character_set(MYSQL * mysql,
                            const char * csname);

πŸ’– DESCRIPTION πŸ’–

So basically this sets the default character set for the current connection. that's the whole vibe. ur connection wakes up and chooses its charset like it's picking an outfit.

it returns zero on success, non-zero on failure. periodt.


✨ PARAMETERS ✨

  • mysql β€” a mysql handle, which was previously allocated by mysql_init(3) or mysql_real_connect(3). like, it has to already exist bestie, u can't just manifest it 🫢
  • csname β€” character set name. just the name, that's it πŸ’…

πŸ‘‘ NOTES πŸ‘‘

  • It's strongly recommended to use mysql_set_character_set() instead of SET NAMES ... since mysql_real_escape_string(3) might fail or deliver unexpected results.
🚨 okay this one matters!! do NOT be out here rawdogging SET NAMES ... and then calling mysql_real_escape_string(3) and acting surprised when it misbehaves. it might fail. it might deliver unexpected results. we do not want that energy. use the function. the function ate. πŸ”₯

⭐ RETURN VALUE ⭐

Zero on success, non zero if an error occurred. that's it, that's the whole report card πŸ“


🌈 SUPPORTED CHARACTER SETS 🌈

the client library supports the following character sets, and honestly? the range is iconic:

  • armscii8 β€” 8 bit character set for Armenian
  • ascii β€” US ASCII character set
  • big5 β€” 2 byte character set for traditional Chinese, Hongkong, Macau and Taiwan
  • binary β€” 8 bit binary character set
  • cp1250 β€” Windows code page 1250 character set
  • cp1251 β€” Windows code page 1251 character set
  • cp1256 β€” Windows code page 1256 character set
  • cp1257 β€” Windows code page 1257 character set
  • cp850 β€” MS-DOS Codepage 850 (Western Europe)
  • cp852 β€” MS-DOS Codepage 852 (Middle Europe)
  • cp866 β€” MS-DOS Codepage 866 (Russian)
  • cp932 β€” Microsoft Codepage 932 (Extension to sjis)
  • dec8 β€” DEC West European
  • eucjpms β€” UJIS for Windows Japanese
  • euckr β€” EUC KR-Korean
  • gb2312 β€” GB-2312 simplified Chinese
  • gbk β€” GBK simplified Chinese
  • geostd8 β€” GEOSTD8 Georgian
  • greek β€” ISO 8859-7 Greek
  • hebrew β€” ISO 8859-8 Hebrew
  • hp8 β€” HP West European
  • keybcs2 β€” DOS Kamenicky Czech-Slovak
  • koi8r β€” KOI8-R Relcom Russian
  • koi8u β€” KOI8-U Ukrainian
  • latin1 β€” CP1252 Western European
  • latin2 β€” ISO 8859-2 Central Europe
  • latin5 β€” ISO 8859-9 Turkish
  • latin7 β€” ISO 8859-13 Baltic
  • macce β€” MAC Central European
  • macroman β€” MAC Western European
  • sjis β€” SJIS for Windows Japanese
  • swe7 β€” 7-bit Swedish
  • tis620 β€” TIS620 Thai
  • ucs2 β€” UCS-2 Unicode
  • ujis β€” EUC-JP Japanese
  • utf8 β€” UTF-8 Unicode
  • utf16 β€” UTF-16 Unicode
  • utf32 β€” UTF-32 Unicode
  • utf8mb4 β€” UTF 4-byte Unicode
πŸ™ˆ if ur wondering: yes, utf8mb4 is right there and yes, it's the main character. but pick whatever ur heart (and ur data) needs. 🧚

πŸŽ€ SEE ALSO πŸŽ€


Version 3.4 of the manual, bestie β€” and that's the whole page, mysql_set_character_set(3) out. go set ur charset, slay ur encoding, and remember: escape ur strings properly. mwah πŸ’œπŸŒˆ

πŸ“¦ where this page comes from