Skip to content

Instantly share code, notes, and snippets.

@Colorfulstan
Created October 9, 2015 16:51
Show Gist options
  • Save Colorfulstan/86e030308712c5a1cdf3 to your computer and use it in GitHub Desktop.
Save Colorfulstan/86e030308712c5a1cdf3 to your computer and use it in GitHub Desktop.
From http://kkovacs.eu/how-not-to-mess-up-encodings How to ensure utf-8 encoded database / html / php
<!-- and, for safety and consistency, also adding this to your html-head output: -->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
//From your PHP code, set your MySQL connection up to use UTF-8 all the time (if not configured so by //default, but usually it is not). This means the following SQL right after connecting to the DB:
set character_set_results=utf8, character_set_client=utf8, character_set_connection=utf8;
//Next, set the HTTP connection to use UTF-8. This means addig this code early on (your head.inc or //similar):
header('Content-Type: text/html; charset=utf-8');
CREATE TABLE `table` (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`TEXT` longtext NOT NULL,
PRIMARY KEY (`ID`),
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment