Doctrine auto将文本字段的长度限制为64512个字符

I have a field in a table of type "text" which usually contain pictures in "base64"; When the images are large, they condifican approximately 200,000 characters. The "text" of the base allows me to store up to 4 million characters. But Doctrine cuts my character string in 64512.

Versions:

  • Doctrine 2.4.4 on Symfony 2.5.3

  • DB: Microsoft SQL Server 2000 - 8.00.2039 (Intel X86) May 3 2005 23:18:38 Copyright (c) 1988-2003 Microsoft Corporation Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)


Declaration of the field.

 /**
 * @var text
 *
 * @ORM\Column(name="mensaje", type="text")
 */
 private $mensaje;

Getter method:

 public function get($value){
    return mb_detect_encoding($value, mb_detect_order(), true) === 'UTF-8' ?
    $value : mb_convert_encoding($value, 'UTF-8');    
 }
 /**
  * Get mensaje
  *
  * @return text
  */
  public function getMensaje()  {
    return $this->get($this->mensaje);
  }

I've tried:

  • Limiting the size of the text with "length"
  • Using other data types such as "clob" or "longtext"
  • Add data to the end of the string to verify that there is a problem of php (no problem with that)

Tnks.

You can use longtext you can store a text with a length up to 4294967292

    TINYTEXT   : 2 ^  8 - 1 = 255 
    TEXT       : 2 ^ 16 - 2 = 65534 
    MEDIUMTEXT : 2 ^ 24 - 3 = 16777213 
    LONGTEXT   : 2 ^ 32 - 4 = 4294967292 

To do so you need to add columnDefinition="longtext" to your field

In my project we use a base64 image (not as large as yours though) and we use a doctrine decimal type. @ORM\Column(name="image", type="decimal", precision=10, scale=4, nullable=true)

We use sql server 2012 though with a varchar(MAX) data type.

When the image is uploaded we base64_encode($imageFile) and persist that...

    public function preUpload()
    {
        if(null === $this->imageFile){
        return;
        }

        $data = file_get_contents($this->imagefile);
        $base64 = base64_encode($data);

        $this->image = $base64;
    }

    public function getImage()  {
    return $this->get($this->Image);
}

The getImage then returns a base64 encoded string that we use to display. Works on a string length 129400 for me. No converting from DB.

PHP truncate all my strings with a several characters. The solution was in the php.ini

mssql.textlimit = 2147483647
; Valid range 0 - 2147483647. Default = 4096.
mssql.textsize = 2147483647

by default was set into 4096, and there be the problem. Thanks for the time!!!