05 Feb
Posted by krisgale as mysql, php, internationalization
if, after painfully specifying character set and collation for your database, all your tables, and all columns within them, you’re still experiencing discrepencies between what your database is storing (eg. strings appear correct from within phpMyAdmin) versus what your website is displaying from database query results (question marks instead of your fancy quotes), try this:
mysql_query(”SET character_set_client = utf8;”);
mysql_query(”SET character_set_results = utf8;”);
those two lines should go right after your mysql_connect() and mysql_select_db().
after several hours of trial-and-error i arrived at the above solution as if by magick. here’s hoping it helps someone else…
| bookmark it! | ||||||
|
2 Responses
Jay Moiron
February 6th, 2008 at 3:19 pm
1Is there anything particularly wrong w/ Pear::DB?
One thing that always chafed my balls about PHP is that none of the DB functionality actually works properly without understanding the vast cultural scaffolding you have to surround it with; requiring manual escaping of data (with several escape functions that don’t actually work littering the stdlib), manually creating db handles, and just all of the error recovery that comes with literally every step of grabbing data from a db.
I haven’t touched a database in a while, and in fact I’ve been looking at non-relational alternatives to classic SQL databases recently and liking what I am seeing tremendously. Read more at my blog link.
krisgale
February 26th, 2008 at 2:37 pm
2not just mysql+php, i’d have to say i’ve always had similar issues in coldfusion and jsp… the database libraries in web scripting languages/platforms really do just provide basic hooks to your database, the rest is left to the developer… though i agree that this stinks, i can’t think of any elegant solutions, especially when it comes to cleansing data prior to an INSERT or UPDATE. in some cases it’s better that it requires implicit value-by-value preparation because otherwise you might eliminate tokens that are useful elsewhere in your code. nature of the beast.
RSS feed for comments on this post · TrackBack URI
Leave a reply
Categories
Archives
Links
Meta
Calendar