adit
adit

Reputation: 33644

storing string that has unicode character in it

I have a string that has the following content:

  \ud83c\udf80NEW STUFF \u0026 SECOND STUFF\n\ud83d\udcf1Sms\/ Kik : 085738566676 \/ veinshop\n\u26d4 All item exclude ongkir\n\u2708Shipping mon-fri\n\ud83d\udcb0BCA only\n\ud83d\ude90JNE\n\ud83c\udfe1 Denpasar-bali

I wanted to store this in my MySQL database however it always gives me empty. I am using doctrine2 ORM as an interface to the database. Here's the entity with the string property:

class Shop
{

 /**
     *
     * @var string
     * @ORM\Column(name="bio", type="string", nullable=true)
     */
    private $bio;

 /**
     * Set bio
     *
     * @param string $bio
     * @return InstagramShop
     */
    public function setBio($bio)
    {
        $this->bio = $bio;

        return $this;
    }

    /**
     * Get bio
     *
     * @return string 
     */
    public function getBio()
    {
        return $this->bio;
    }
}

When I set this Shop entity with the bio and call persist on the entity. The stored value is NULL. I've set my table collation to utf8mb4 and my charset in dbo to utf8mb4

Upvotes: 2

Views: 722

Answers (1)

nurikabe
nurikabe

Reputation: 4010

You probably have a config that looks something like this:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                dbname: %database_name%
                ...
                charset: utf8mb4

Make sure charset is set to utf8mb4. This is your connection collation.

Upvotes: 3

Related Questions