php.net |  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
Votes:3
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wrobel at wsb-nlu dot edu dot pl
New email:
PHP Version: OS:

 

 [2012-01-20 12:04 UTC] wrobel at wsb-nlu dot edu dot pl
Description:
------------
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 http://support.microsoft.com/kb/239530)
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?




Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-24 11:32 UTC] redman dot naw at gmail dot com
Hi,
-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] ssufficool@php.net
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 
strategy.
 [2013-06-12 04:21 UTC] ssufficool@php.net
-Summary: Problem storing UTF data +Summary: PDO_DBLIB: Problem storing UTF data
 [2014-01-01 12:41 UTC] felipe@php.net
-Package: PDO related +Package: PDO DBlib
 [2016-09-12 21:19 UTC] adambaratz@php.net
-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] adambaratz@php.net
This is a limitation of how PDO handles types.

I implemented a hackish solution here:
https://github.com/wayfair/php-src/commit/0190df6da7a4c39b235a75161fdc880acde5c28f

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:
https://github.com/php/php-src/pull/2017#discussion_r72349801
 [2016-09-12 21:23 UTC] adambaratz@php.net
-Summary: PDO_DBLIB: cannot quote strings as NVARCHAR +Summary: cannot quote strings as NVARCHAR
 [2017-03-15 15:41 UTC] adambaratz@php.net
I posted an RFC to address this issue:
https://wiki.php.net/rfc/extended-string-types-for-pdo

It's currently being voted on.
 [2017-04-10 20:48 UTC] adambaratz@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: adambaratz
 [2017-04-10 20:48 UTC] adambaratz@php.net
Closing, as the RFC was accepted. This functionality will be available in PHP 7.2:
https://github.com/php/php-src/commit/4afce8ec8c6660ebd9f9eb174d2614361d1c6129
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 11:01:31 2025 UTC