Charset problem PHP + MYSQL + new server

Asked

Viewed 3,006 times

-1

I work for a reseller of lodgings and I have a strange problem...

I recently acquired a server in ALOG, before I had a server in the hostgator, so I exported it through the Cpanel schema of all accounts.

Every site on this server has a PHP control panel to feed a Mysql database, the data registered in this panel before the migration, even after the migration are perfect, special characters, all clean.

First strange fact.

To) Once on the new server, I decide to register the word "Are", he saves "Are in the bank, da para ver pelo phpMyAdmin.

B) On the old server, when saved the word "are", I see in phpMyAdmin the word are like this : "SANE"

Cool that always worked like this, when in the frontend of the site I search in the bank, it returns me always the correct word.

As I exported the account, all charset settings of the sign-up files/view files are equal, so are the database settings.

Okay, I always wondered why it worked in the B way, but I was happy because it worked.

in my WHM, my php.ini is configured with charset iso-8859-1 same as my old server.

1st Problem:

But there appears the first problem, the words on the panel appear without the correct accentuation, for example "Description", appears "Description§§§§§§", now how? the charset is the same! the file is the same, the database has been exported and imported..

if I switch to utf-8, ready! works and appears right, but then the server is different the configuration, the new utf-8, the old iso-8859-1, I live with it, alive, but the problem is that there are more problems so I try to leave the 2 equal to go eliminating possibilities.

2nd problem: This is strange... I created a page, this page is with the metatag

<meta charset="utf-8" > 

but her encoding is iso-8859-1. the bank is like latin1_swedish_ci that is iso-8859-1 right? the table, everything, exactly like the database configuration of my old server, which works.

But when I register words, if they end with special characters, the problem

for example the phrase "is dull ó data, ã, implicit, meeting" when saved, it saves "is dull ó data, ã, implicit, meeting" in the bank and at the time of showing it shows "is dull ó data, ã, implicit, meeting"

but if I put some special character at the end, like "reuniã" it disappears me with the last character and shows nothing!

But if I put 2 special characters, then he obeys, like "meek," then he shows. Can you understand? if I put the only letter "Is" doesn’t work, if I put "ÉÉ" works!!

if you don’t believe, take a look http://www.heytec.com.br/test/


And that’s as much as I could, because even though I knew this configuration was correct because it works on the other server, I changed it and says all possible combinations.

had time to return me "?" and worse, this was as far as I got!

Can any charitable soul give me a light?? I haven’t slept for 2 days because of it.

DIRECT SEARCH IN PUTTY IN DATABASE - NEW SERVER

                             |
-> +----+----------------------------------------------+
-> |  1 |                                              |
-> |  2 | 1                                            |
-> |  3 | é maçaa ó dados, ã, implícito, reunião       |
-> |  4 | é maçaa ó dados, ã, implícito, reunião       |
-> |  5 | é maçaa ó dados, ã, implícito, reunião       |
-> |  6 | é maçaa ó dados, ã, implícito, reunião       |
-> |  7 | é maçaa ó dados, ã, implícito, reunião       |
-> |  8 | Acentuação 123                               |
-> |  9 | Acentuação 456                               |
-> +----+----------------------------------------------+
-> 9 rows in set (0.00 sec)

DIRECT SEARCH IN DATABASE, OLD SERVER

 select * from dados;
+----+-----------+
| id | valor     |
+----+-----------+
|  1 | ma&#231;a |
|  2 | ol&#225;  |
|  3 | teste     |
+----+-----------+
3 rows in set (0.00 sec)

One detail I forgot to mention, is that if I search the variable for POST, it already has the problem, and if I put the special character directly in the query, it works, the problem is in the rescue of it in PHP, now because I do not know, apache? config in the php.ini?

I just returned the php.ini as utf8, so I can have the data that has already been registered in order.

so gets my test environment screen

"� ma�aa � dados, �, impl�cito, reuni�o"

---------------------- CONFIG PHP NEW SERVER

www.heytec.com.br / test/ test.php

---------------------- CONFIG PHP OLD SERVER

162.144.115.36 / ~heytecco / test/

  • Description§means that the data is recorded in the BD as utf-8 but being shown in iso-8859-1, OU is going through 2 UTF-8 encodings by mistake. View the binary data in the database, and add the question to be sure (can be converted to hexadecimal).

  • I took your test and it’s all right here with the accent. http://i.stack.Imgur.com/z5bIx.png - High chance of BD being in UTF-8 even, and by displaying in iso, does not come out right.

  • test putting only a special character, type IS, or putting only one in the whole sentence and it at the end!

  • For starters, you are mixing a UTF-8 page with an iso form, what’s the idea? It seems to me that you are trying to solve by trial and error. If it’s for testing, you can try for UTF-8 at all and display the old database data to see if it works. In addition, you need to test everything without utf8 Access/Code in PHP, otherwise it becomes crazy. Charset is a very simple thing, the problem is that few people spend time to understand, and so we see problems with it all the time.

  • Precisely, I am in trial and error, I have left everything in UTF-8, I have left everything in ISO, I have already mixed the 2, that there was the config that I got closer to the solution, if I leave php.ini in utf8 it does not give me problem in display of the old data, but the default config is iso on the old server, I’m not getting anything.!

  • Mixed will always give problem. The important thing is you detect how the data is. The best would be to see the bytes, then you would be absolutely sure. All indicates that it is UTF-8, but only analyzing the bytes numerically instead of playing on the screen.

  • Friend Danilo I advise you to install an automatic corrector, to correct errors in your text.

  • @Danilo, take your urgent form off the air, It is completely open to do SQL Injection. Jajá some joker erases your entire BD.

  • is a test comic, on a test account, has nothing in it, is soh to try to solve the problem, thanks for the concern!

  • For the test page set the communication with the database to utf-8, I’m not sure what extension of PHP you’re using, but here’s a way to do this: http://php.net/manual/en/function.mysql-set-charset.php and please save the document as utf-8 as well, or I’ll create a new one.

  • http://php.net/manual/en/mysqlinfo.concepts.charset.php. on this page you will find information on how to configure the charset for other pages. but still, making it work on the test page is different from making it work on the system.

  • When I do this, if these charset configs, the error passes to ??? ma??? aa ???? data, ??? impl???? quote, reuni???? o, I had already done these tests, I remade them now by way of doubt, tb created a new utf8 file for testing, nothing... Have a thing, when sending from and a form, a word like "apple" per post, and give an echo $_POST[field] it already returns me with problem, without even inserting in the comic

  • maybe it’s something with the same server. if you give the post and the character already comes indecipherable hehe. see if the solution to this link resolves http://www.howtoforge.com/forums/showthread.php?t=27230

  • I’ll test it, buddy, I’ll answer you, thanks!

  • Buddy, you know how I can do that at the WHM??

  • I managed to make the change directly by SSH, but I was not successful, I tested all the options cited in the presented forum. = [ I think I’ll go back to the old server.. q Zica..

  • you restarted the apache?

Show 12 more comments

2 answers

1

I believe you have created the new database with the wrong charset, and the tables of this database are inheriting this new charset.

See which is the charset of your old database and configure the new one with it.

This does not explain why the database values are being written as html entities, but it does not cost to try.

  • Both banks are latin1, the database, the tables, the Fields, I think that should not be in the database the problem, because when resgato by post the data, they come back with problem, even without inserting in the database! =/

  • 1

    Cesarmiguel is answered very clearly is that it should be the charset of the banks that is disfigured, if the answer is wrong is another story.

  • I had this problem a few months ago with phpMyAdmin. I put the default settings in utf8_general_ci so I was creating the tables without worrying about the settings. One day, I started having problems in a new table. I then realized that Phpmyadmin had changed the default setting, became latin1_swedish_ci! Then I changed the char-set to return to utf8, the default setting in utf8_general_ci and everything is in order again. Then see your default setting in Phpmyadmin because it is possible that it imposes a value that is not what you want.

0

I’ve been in the same trouble.

Keep this tag in your html:

<meta charset="utf-8" >

And in PHP, use the utf8_encode function().

Example, considering that the $variable came from a SELECT:

utf8_encode($variavel);

This normalizes the accents and removes the html.

Browser other questions tagged

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