{"id":466,"date":"2017-08-27T01:02:44","date_gmt":"2017-08-27T01:02:44","guid":{"rendered":"http:\/\/www.gnial.com.br\/gnialhelp\/?p=466"},"modified":"2019-11-26T10:31:33","modified_gmt":"2019-11-26T13:31:33","slug":"parte-2-de-2-mysql-php-iso-utf8-utf8_general_ci-utf8_unicode_ci","status":"publish","type":"post","link":"http:\/\/www.gnial.com.br\/gnialhelp\/parte-2-de-2-mysql-php-iso-utf8-utf8_general_ci-utf8_unicode_ci\/","title":{"rendered":"Parte 2 de 2 &#8211; MYSQL, PHP, ISO, utf8, utf8_general_ci, utf8_unicode_ci"},"content":{"rendered":"<p><a href=\"http:\/\/www.gnial.com.br\/gnialhelp\/parte-1-de-2-mysql-php-iso-utf8-utf8_general_ci-utf8_unicode_ci\/\">Artigo 1<\/a><\/p>\n<p>Artigo 2<\/p>\n<h2>Usando PHP<\/h2>\n<p>Caso precise codificar e descodificar, \u00e9 nesta ordem:<\/p>\n<p>utf8_encode() &gt; html_entity_decode() &gt; htmlentities() e em \u00faltimo caso, se nada disso funcionar, use o header(&#8216;content-type text\/html charset=utf-8&#8217;);<\/p>\n<h2>Usando META TAGS<\/h2>\n<p>&lt;meta charset=&#8221;utf-8&#8243;&gt;<br \/>\n&lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=UTF-8&#8243; &gt;<\/p>\n<h2>Conex\u00e3o PDO<\/h2>\n<p>MySQL (PDO):<br \/>\n$dsn = &#8220;mysql:host=localhost;dbname=world;charset=utf8&#8221;;<\/p>\n<h2>MySQL<\/h2>\n<p>MySQL:<br \/>\nCREATE DATABASE nome_bd CHARACTER SET UTF8;<\/p>\n<p>COLLATE<br \/>\nIn short: <strong>utf8_unicode_ci<\/strong> uses the Unicode Collation Algorithm as defined in the Unicode standards, whereas utf8_general_ci is a more simple sort order which results in &#8220;<strong>less accurate<\/strong>&#8220;[preciso] sorting results. But faster<\/p>\n<p><strong>Explicacao de unicode and general<\/strong><br \/>\nutf8_general_ci<br \/>\nutf8_unicode_ci<br \/>\nhttps:\/\/pt.stackoverflow.com\/questions\/43281\/qual-collate-utf-8-%C3%A9-o-mais-apropriada-para-web-multi-linguagem<\/p>\n<p>SQL:<br \/>\n<strong>database<\/strong><br \/>\nALTER DATABASE databaseName CHARSET = UTF8 COLLATE = utf8_general_ci; \/\/utf8_unicode_ci<br \/>\n<strong>table<\/strong><br \/>\nALTER TABLE tableName CONVERT TO CHARACTER SET utf8;<br \/>\n<strong>for a specific column in a table<\/strong><br \/>\nALTER TABLE columnName COLLATE utf8_general_ci<\/p>\n<p><em>: esse i no final \u00e9 ignora busca sensecade, minuscula e maiuscula<\/em><\/p>\n<h2>Entenda\u00a0CHARSET e COLLATE<\/h2>\n<p>CHARSET e COLLATE s\u00e3o coisas distintas, no MySQL, cada CHARSET possui COLLATEs, cada um com sua particularidade. O intuito deste Wiki n\u00e3o \u00e9 explicar as caracter\u00edsticas de cada um deles, pois pode ser visto da documenta\u00e7\u00e3o do MySQL, mas daremos um pequeno descritivo entre latin1_general_ci, latin1_general_cs e latin1_swedish_ci.<\/p>\n<h2>COLUNA texto, tamanhos<\/h2>\n<blockquote><p>Type | Maximum length<br \/>\n&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nTINYTEXT | 255 (2 8\u22121) bytes<br \/>\nTEXT | 65,535 (216\u22121) bytes = 64 KiB<br \/>\nMEDIUMTEXT | 16,777,215 (224\u22121) bytes = 16 MiB<br \/>\nLONGTEXT | 4,294,967,295 (232\u22121) bytes = 4 GiB<\/p>\n<p>Type | A= worst case (x\/3) | B = best case (x) | words estimate (A\/4.5) &#8211; (B\/4.5)<br \/>\n&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nTINYTEXT | 85 | 255 | 18 &#8211; 56<br \/>\nTEXT | 21845 | 65,535 | 4854.44 &#8211; 14,563.33<br \/>\nMEDIUMTEXT | 5,592,415 | 16,777,215 | 1,242,758.8 &#8211; 3,728,270<br \/>\nLONGTEXT | 1,431,655,765 | 4,294,967,295 | 318,145,725.5 &#8211; 954,437,176.6<\/p><\/blockquote>\n<p>&nbsp;<\/p>\n<p>Tive este mesmo problema e consegui resolver da seguinte maneira:<br \/>\nNo meu arquivo de conex\u00e3o com o banco, coloquei o c\u00f3digo abaixo:<\/p>\n<p>echo utf8_encode($exibe[&#8216;recadao_mensagem&#8217;]);<br \/>\nou<br \/>\nmysql_query(&#8220;SET NAMES &#8216;utf8&#8242;&#8221;);<br \/>\nmysql_query(&#8216;SET character_set_connection=utf8&#8217;);<br \/>\nmysql_query(&#8216;SET character_set_client=utf8&#8217;);<br \/>\nmysql_query(&#8216;SET character_set_results=utf8&#8217;);<br \/>\nou<br \/>\nini_set(&#8216;default_charset&#8217;, &#8216;UTF-8&#8217;);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Artigo 1 Artigo 2 Usando PHP Caso precise codificar e descodificar, \u00e9 nesta ordem: utf8_encode() &gt; html_entity_decode() &gt; htmlentities() e em \u00faltimo caso, se nada disso funcionar, use o header(&#8216;content-type text\/html charset=utf-8&#8217;); Usando META TAGS &lt;meta charset=&#8221;utf-8&#8243;&gt; &lt;meta http-equiv=&#8221;Content-Type&#8221; content=&#8221;text\/html; charset=UTF-8&#8243; &gt; Conex\u00e3o PDO MySQL (PDO): $dsn = &#8220;mysql:host=localhost;dbname=world;charset=utf8&#8221;; MySQL MySQL: CREATE DATABASE nome_bd CHARACTER [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":565,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","has-thumbnail"],"_links":{"self":[{"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/comments?post=466"}],"version-history":[{"count":2,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/posts\/466\/revisions"}],"predecessor-version":[{"id":469,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/posts\/466\/revisions\/469"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/media\/565"}],"wp:attachment":[{"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/media?parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/categories?post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.gnial.com.br\/gnialhelp\/wp-json\/wp\/v2\/tags?post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}