Windows with php the utf-8 characters are correct and not in Linux?

Asked

Viewed 254 times

0

I created php pages in windows 2012 with php (to migrate from Asp to php)

The pages in php are:

HTML5 (made in Notpad++ in UTF-8 Encoding)

Has < meta charset="UTF-8" > in the head

Accesses in Mysql: $pdo = new PDO("mysql:host=xxxx.mysql.dbaas.com.br;dbname=xxx; charset=utf8", "login", "senha")

fields in tables = latin1_general_ci

RESULT: Accentuation and perfect characters in Mysql data and text on pages.

PROBLEM in php Linux:

I transferred the same pages to Linux and accessing the SAME Mysql BD

And made a mistake in accentuating:

Mysql data with ERROR and other text on the correct pages

COMPLEMENT

In the meantime: I changed the version to php 7.1 created a table in Linux Mysql And the accent is correct.

I consider this matter closed.

  • 2
  • A few months ago, I used these guidelines to create the pag.php and it all worked out. I am intrigued because it is OK in Windows 2012 with php and with pure php error. Does windows/php have different configuration? We do not have access to Locaweb. Thank you.

  • I haven’t tried. I’m going to download these 2 and run some tests. What I like about Notepad is an FTP app that downloads when saving the file. It’s very practical. Worth the tip !!!

  • Atom, Sublime and Visual Studio do not run on Windows Vista. I tried now.

  • It must be because Linux is better than ruindows ( ° ʖ °)

1 answer

0

I was able to correct the accent:

Mysql Table: put in Collation = utf8_unicode_ci

Connection to BD with PDO

$pdo = new PDO("mysql:host=XXX;dbname=XXX; charset=utf8", "XX", "XX", array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

Note: This array corrected accentuation errors.

And now the HTML text and BD data are correct.

  • I upgraded to PHP 7.1 and the pages I DIDN’T PUT THE ARRAY UP WERE PERFECT IN ACCENTS. It seems that the 7.1 hit the charset compatibility. Good surprise !!!

  • 1

    The array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") is the same as the $pdo->exec('SET CHARACTER SET utf8');, only self executed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.