数组原则到文本字段(而不是长文本) [英] Array Doctrine to text field (and not longtext)

查看:68
本文介绍了数组原则到文本字段(而不是长文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ORM原则,我注意到数组原则在数据库中生成一个长文本字段。有没有一种生成文本字段的方法?

Using ORM Doctrine, I noticed that an array Doctrine generate a longtext field in database. Is there a way to generate text field ?

谢谢

/**
 * @var array
 *
 * @ORM\Column(name="my_field", type="array", nullable=true)
 */
private $myField;


推荐答案

仅供参考,如果有人偶然发现这个问题:文本字段的 最大大小 存储要求 是两件事。

Just for the record if anyone stumbles on this question : maximum size and storage requirements of a text field are two very different things.

在MySQL中(我猜还有其他SQL引擎),可变长度的字符串类型(例如TEXT或LONGTEXT)使用长度存储前缀数据长度前缀需要一到四个字节,具体取决于数据类型。

In MySQL (and I guess other SQL engines), variable-length string types like TEXT or LONGTEXT are stored using a length prefix plus data. The length prefix requires from one to four bytes depending on the data type.

因此,基本上,TEXT和LONGTEXT之间的区别只是字段可以容纳的最大字符串长度。在磁盘上,它将采用相同的大小(两个或三个字节除外)

So, basically, the difference between TEXT and LONGTEXT is just the maximum length of the string the field can hold. On disk, it will take the same size (except for two or three bytes)

TINYBLOB, TINYTEXT             --> L + 1 bytes, where L < 2^8
BLOB, TEXT                     --> L + 2 bytes, where L < 2^16
MEDIUMBLOB, MEDIUMTEXT         --> L + 3 bytes, where L < 2^24
LONGBLOB, LONGTEXT             --> L + 4 bytes, where L < 2^32




哦,要注意字符集。特别是在使用utf8 Unicode字符集时,必须记住,并非所有字符都使用相同数量的字节,并且每个字符最多需要三个字节

Oh, and beware of the character set. In particular, when using the utf8 Unicode character set, you must keep in mind that not all characters use the same number of bytes and can require up to three bytes per character

来源: https:// dev .mysql.com / doc / refman / 5.1 / en / storage-requirements.html

这篇关于数组原则到文本字段(而不是长文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆