开发者

data storage and retrieval in the database

in PHP while using a form the details what we enter has to be stored in the database... is it like the data gets stored using any encoding scheme in the database...bcoz when i use a different language except English the storage shows some absurd codes in the DB...but 开发者_JAVA百科when I retrieve the data..it comes as I had enetered in standard English...


You need to check the font encoding in the database. The same goes for the html.You should also reed the php manulal on encoding og deconding php strings


I think by 'language' you actually mean 'character encoding'. Please go ahead and read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!). It will save you (and others ;) a lot of trouble in the future.

The basic thing is that you have to know the encoding of your characters at every stage of your processing and storage, because otherwise, you can not really ensure proper, readable output.

That your setup is working right now is more or less a lucky incident, but as soon as you use your database from a different app (or change the way your current app deals with strings), things can break down pretty fast.

You want to ensure that all characters in your database are stored with the same encoding (preferably one of the UNICODE versions), so that you can convert them reliably to any other encoding you might need in your apps.


Working with different character sets can get a bit tricky at times, especially when juggling data between the application and data layers. There are plenty of tutorials / blog posts to be found on the web - a quick google for "PHP MySQL UTF data" brings up a fair few results. But in summary:

PHP

PHP doesn't have native very good Unicode support yet: it's far better to utilise a third-part extension, of which MBString is the best.

MySQL

You need to make sure your tables/columns are correctly setup to support UTF character data. This is just a matter of creating/altering the columns in question to use a UTF character set:

ALTER TABLE theTabel MODIFY formTextField VARCHAR(255) CHARACTER SET utf8

HTML

Finally, you need to make sure your HTML is being served with the correct headers

Content-type: text/html; charset=utf-8
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜