|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60818 cannot quote strings as NVARCHAR
Submitted: 2012-01-20 12:04 UTC Modified: 2017-04-10 20:48 UTC
Avg. Score:3.3 ± 1.2
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:2 (66.7%)
From: wrobel at wsb-nlu dot edu dot pl Assigned: adambaratz (profile)
Status: Closed Package: PDO DBlib
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-01-20 12:04 UTC] wrobel at wsb-nlu dot edu dot pl
I have a problem storing UTF data on MSSQL using pdo_dblib.
In the following query:
   EXECUTE p_proc id = :id, @name = :name
I cannot bind the ":name" param using the N'string' notation required by SQL Server (see
You cannot get around this by typing:
   EXECUTE p_proc id = :id, @name = N:name
because binding fails on N:name

The same problem happens with qoute function - it allways quotes with '' a never with N'' - perhaps there should be a new param like PDO::PARAM_STR to tell that with deal with a Unicode value?


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-24 11:32 UTC] redman dot naw at gmail dot com
-you should use utf8_decode to convert UTF8 character to ISO-8859-1(latin-1) character
- i use this function with MySQL, that's work :D
 [2012-04-02 03:28 UTC]
This will require a re-write of the PDO_DBLIB to allow the use of the "encoding" 
option. After that, all queries and parameter will require you to encode them 
before binding with utf8_encode(). You will also have to decode them using 
utf8_decode() when returned from the server. I was working to bring full Unicode 
support to the driver, but it would have broken so much code I had to rethink the 
 [2013-06-12 04:21 UTC]
-Summary: Problem storing UTF data +Summary: PDO_DBLIB: Problem storing UTF data
 [2014-01-01 12:41 UTC]
-Package: PDO related +Package: PDO DBlib
 [2016-09-12 21:19 UTC]
-Summary: PDO_DBLIB: Problem storing UTF data +Summary: PDO_DBLIB: cannot quote strings as NVARCHAR -Type: Bug +Type: Feature/Change Request
 [2016-09-12 21:19 UTC]
This is a limitation of how PDO handles types.

I implemented a hackish solution here:

It's not clean enough for general use, but could work in a pinch if you're willing to do a custom build.

I sketched out a better solution here:
 [2016-09-12 21:23 UTC]
-Summary: PDO_DBLIB: cannot quote strings as NVARCHAR +Summary: cannot quote strings as NVARCHAR
 [2017-03-15 15:41 UTC]
I posted an RFC to address this issue:

It's currently being voted on.
 [2017-04-10 20:48 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: adambaratz
 [2017-04-10 20:48 UTC]
Closing, as the RFC was accepted. This functionality will be available in PHP 7.2:
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Aug 13 02:05:44 2022 UTC