TOgakangaroo Posted January 18, 2007 Share Posted January 18, 2007 I posted this in the MySQL forum but upon thinking about it, this should probably go here I am working on a large project which involves among other things storing names with international characters in MySQL tables. This data is typically delivered via spreadsheets so I have written a utility to do upload a file and do just that. I am running into the problem currently that certain characters (i.e. the spanish e with an accent) will not import correctly causing the rest of the name to be cut off.So for example, running$term = 'México';mysql($database_info, "INSERT INTO tblSomeTable VALUES $term"); will store only 'M'.If I hardwire the term into the querymysql($database_info, "INSERT INTO tblSomeTable VALUES 'México'");It doesn't cut off but does insert gibberishOne intersting thing that I've found is that everything works out fine when the variable is passed through the HTTP Post Methodmysql($database_info, "INSERT INTO tblSomeTable VALUES $_POST['name']");where $_POST["name"]='México' from a form imputthis inserts correctly.My intuition is that I need to set PHP to use the same encoding that HTTP POST uses but I don't know if that's true nor exactly how to do that. Has anybody run into this problem before/can help me out?Thanks a lot for your help. Link to comment https://forums.phpfreaks.com/topic/34695-storing-international-characters-through-php/ Share on other sites More sharing options...
anatak Posted January 18, 2007 Share Posted January 18, 2007 I hope you are using utf charsetyou have to change the headers to utfyou have to change in the html the content to utfyou also have to modify mysqlcharacter set and collation should be utfand you have to run mysql_query(SET NAMES utf8); here you will find a ton of information.http://dev.mysql.com/doc/refman/5.0/en/charset-connection.htmlif you plan to use ADOdb connections you have to do some things differentrun a queryshow variables like %cand then you should have most of it in utfread this page (about adodb connections wich is what i use but it will still help you to understand)http://www.adviesenzo.nl/examples/php_mysql_charset_fix/anatak Link to comment https://forums.phpfreaks.com/topic/34695-storing-international-characters-through-php/#findComment-163528 Share on other sites More sharing options...
TOgakangaroo Posted January 18, 2007 Author Share Posted January 18, 2007 Thanks for the replies and the linksI am starting to wonder if this might be a php problem first and foremost (after all it DOES insert fine when I go through the $_POST)My thought is that there is some sort of header placed on it when the data is sent through HTTP Post and PHP applies different rules to it when it is placed in $_POST. The question then becomes what is it exactly that is done to the data and how do I make PHP do that to my data as well.I have not read your links yet and am just posting some ideas. That second link actually looks quite promising.I am pretty sure that everything the database is set to work on UTF-8 (the sysadmin spent all last week making these changes) however if PHP is not then I don't understand why it would work ok in the $_POST variable.Anyways, thanks a lot for the help. I'll post a big thanks back on here if it works. (And an angry letter to THE INTERNET if it doesn't) Link to comment https://forums.phpfreaks.com/topic/34695-storing-international-characters-through-php/#findComment-163539 Share on other sites More sharing options...
anatak Posted January 18, 2007 Share Posted January 18, 2007 read this and then write the angry letterhttp://www.joelonsoftware.com/articles/Unicode.htmlthis is the single most important page on the internet about character :) Link to comment https://forums.phpfreaks.com/topic/34695-storing-international-characters-through-php/#findComment-164021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.