简体   繁体   English

数据库中的数据存储和检索

[英]data storage and retrieval in the database

在PHP中使用表格时,我们输入的详细信息必须存储在数据库中...就像数据使用任何编码方案存储在数据库中一样... bcoz,当我使用除英语之外的其他语言时,存储显示DB中有些荒谬的代码...但是当我检索数据时,它就像我用标准英语所迷一样...

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 html也是如此。您还应该在编码和解构php字符串时使用php手册

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!) . 请继续阅读《绝对绝对是每个软件开发人员的绝对最低知识》,肯定要了解Unicode和字符集(无借口!) 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. 您要确保数据库中的所有字符都使用相同的编码(最好是UNICODE版本之一)存储,以便可以将它们可靠地转换为应用中可能需要的任何其他编码。

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. 在网上可以找到大量的教程/博客文章-一个用于“ PHP MySQL UTF data”的快速google搜索结果。 But in summary: 但总而言之:

PHP 的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. PHP没有 本地 很好的Unicode支持不过它是更好地利用第三部分的扩展,它的MBSTRING是最好的。

MySQL 的MySQL

You need to make sure your tables/columns are correctly setup to support UTF character data. 您需要确保正确设置了表/列以支持UTF字符数据。 This is just a matter of creating/altering the columns in question to use a UTF character set: 这只是创建/更改相关列以使用UTF字符集的问题:

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

HTML 的HTML

Finally, you need to make sure your HTML is being served with the correct headers 最后,您需要确保HTML带有正确的标头

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM