shane18 Posted October 18, 2009 Share Posted October 18, 2009 When mysql sends data to php..... does it convert it from the mysql character set to the php one or what... i don't understand Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 It uses connection's charset Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 can you explain? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 http://dev.mysql.com/doc/refman/5.0/en/charset-connection.html Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 what im saying is that..... php client is set to receive UTF-8..... and the .php file is saved in ISO-8859-1... hows that work? or w/e.. can you explain how php and mysql work charset wise... Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 It depends on how you set up your connection to mysql in php. By default it uses default charset as specified in mysql's ini file. To set up desired charset use 'SET NAMES ... ' query. Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 so PHP has a default way to connect to MySQL? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 No. Whatever connects to MySQL uses default settings, unless specified otherwise. Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 im sorry that im like an idiot with character set stuff... but can you explain step by step how when you get data from a mysql row.. how does it work character set wise... Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 Honestly, I do not know enough detail to be able to explain that. I just always take care to set up everything to UTF8 and the stuff just works ;P Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 so ur saying that if it works don't worry about it? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 Depends... I would make sure that my code sets up connection charset explicitly. Depending on default values can result in difficult to track bugs, when moving application from one server to another. Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 u got a check list i can check to make sure my php/mysql site is fully setup for UTF-8? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 It goes something like this. 1. Set up all tables and columns that can store non ASCII characters as utf8 2. Save all PHP scripts in UTF-8 without BOM. 3. Declare all HTML pages encodings as utf8 4. Set up PHP to MySQL connection as utf8 - for mysql_connect mysql_connect('','',''); mysql_query("SET NAMES 'utf8'"); - for mysqli $db = new mysqli('','','',''); $db->set_charset('utf8'); Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 whats BOM? and thanks for the list Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 http://en.wikipedia.org/wiki/Byte-order_mark If you save your PHP scripts with BOM you can get some nasty header errors and/or see some funny characters at the beginning of each page. Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 I looked at that page, but can you summerize BOM in a few sentences.. and how to not save it in BOM... Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 In few sentences... let's say unicode files can be stored in two ways, and BOM is the information on which way has been used for given file. Many text editors allow you to choose whether to use BOM or not. For quick fixes I use Notepad++. Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 u saved my programming career man, cuz i can code fine but i hate the whole character set shit.. thank god for UTF-8...... thats the best character set if u want everything right? Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 18, 2009 Author Share Posted October 18, 2009 btw, whats the database collation do... and column collations do... Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 18, 2009 Share Posted October 18, 2009 http://www.phpfreaks.com/blog/mysql-university-how-to-use-charsets-and-collations-properly Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 19, 2009 Author Share Posted October 19, 2009 that link wasn't much help.. what i mean is... why does it matter what the DATABASE collation is... searches only happen on tables right? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 19, 2009 Share Posted October 19, 2009 Database collation/charset is just a default colllation/charset for new tables, and table collation/charset is just default collation/charset for new columns. Quote Link to comment Share on other sites More sharing options...
shane18 Posted October 21, 2009 Author Share Posted October 21, 2009 thanks man, so my last question is that.... so by following It goes something like this. 1. Set up all tables and columns that can store non ASCII characters as utf8 2. Save all PHP scripts in UTF-8 without BOM. 3. Declare all HTML pages encodings as utf8 4. Set up PHP to MySQL connection as utf8 - for mysql_connect mysql_connect('','',''); mysql_query("SET NAMES 'utf8'"); - for mysqli $db = new mysqli('','','',''); $db->set_charset('utf8'); my stuff will be fully setup for UTF-8? Quote Link to comment Share on other sites More sharing options...
Mchl Posted October 22, 2009 Share Posted October 22, 2009 That's what I do and it works for me. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.