2

I'm executing this piece of SQL in SQL Server Management Studio.

  INSERT INTO cy_company ( cy_company.cy_name, cy_company.cy_address, cy_company.cy_manager, cy_company.cy_number )
VALUES ( '杭州运输公司1', 'Road', '张三', 1234567 )

When I query the table though I'm seeing this:

??????1 Road    ??  1234567

I had been scratching my head all evening as I thought it was my PHP code that was wrong, I've set the encoding to UTF8 in meta, in header and the php files are all UTF8 but I just did a print of the SQL and it's printing fine, when I manually run the printed SQL though it doesn't insert. My IDE also doesn't like showing me values of UTF8 strings properly but when printed it's fine.

The columns are NVARCHAR.

Jay Croghan
  • 445
  • 3
  • 16
  • Declare your literal strings as an `nvarchar`, not a `varchar`. `N'杭州运输公司1'` not `'杭州运输公司1'`, `N'张三'` not `'张三'`. – Thom A Mar 19 '19 at 16:01
  • Wow. I needed to add that to my SQL too and it's fine. – Jay Croghan Mar 19 '19 at 16:15
  • @Larnu Your comment should be taken as the accepted answer for this. It works thanks – MindRoasterMir Aug 08 '21 at 19:45
  • @Larnu add it as an answer and I'll accept it. – Jay Croghan Jun 10 '22 at 08:28
  • The question is closed as a duplicate, @JayCroghan . Though I would personally also close this as a dupe of [What is the meaning of the prefix N in T-SQL statements and when should I use it?](https://stackoverflow.com/questions/10025032/what-is-the-meaning-of-the-prefix-n-in-t-sql-statements-and-when-should-i-use-it) – Thom A Jun 10 '22 at 08:30
  • Ah I didn't even notice the closure @Larnu can I close it as duplicate myself? – Jay Croghan Jun 11 '22 at 12:49
  • The question is already closed, @JayCroghan . It was closed 3 years ago – Thom A Jun 11 '22 at 13:01

0 Answers0