php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72414 MSSQL BindParam with UTF8 Character then Char modified
Submitted: 2016-06-15 14:48 UTC Modified: 2016-09-14 21:47 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: sungtae542 at gmail dot com Assigned: adambaratz (profile)
Status: Closed Package: PDO DBlib
PHP Version: 7.0.7 OS: Ubunbu 16.04
Private report: No CVE-ID: None
 [2016-06-15 14:48 UTC] sungtae542 at gmail dot com
Description:
------------
MSSQL BindParam with UTF8 Character in PHP 7.0.4 and PHP 7.0.7 
then UTF8 character is modified.
PHP 5.5.6 is OK. 
PHP 7.0 without bindparam and just pdo-dblib with UTF8 is ok.
PHP 7.0 with bindparam pdo-mysql UTF8 is ok.

PHP 7.0.4-7ubuntu2.1 (Ubuntu 16.04 Package)
PHP 7.0.7 (php-7.0.7.tar.gz)
Ubuntu 16.04 + PHP7.0.4 PDO_dblib + parambind(UTF8) + mssql : Fail
Ubuntu 16.04 + PHP7.0.7 PDO_dblib + parambind(UTF8) + mssql : Fail
Ubuntu 16.04 + PHP7.0.? PDO_dblib + parambind(Ansi) + mssql : OK
Ubuntu 14.04 + PHP5.5.9 PDO_dblib + parambind(UTF8) + mssql : OK
Ubuntu 16.04 + PHP7.0.4 PDO_dblib + UTF8 query + mssql : OK
Ubuntu 16.04 + PHP7.0.4 PDO_mysql + parambind(UTF8) + mysql : OK
Ubuntu 16.04 + freetds + tsql + mssql : OK

Test script:
---------------
# with bindparam
$pdo = new PDO("dblib:host=$dbIp;dbname=$dbName;charset=UTF-8", $dbId, $dbPw);
#$username = 'username1';
$username = '한글';
$sth = $pdo->prepare("select * from test_table where username = :username");
$sth->bindParam (':username', $username);
$sth->execute();
$row = $sth->fetch(PDO::FETCH_OBJ);
var_dump($row);

#without bindparam
$pdo = new PDO("dblib:host=$dbIp;dbname=$dbName;charset=UTF-8", $dbId, $dbPw);
#$username = 'username1';
$username = "'" . "한글" . "'";
$sth = $pdo->prepare("select * from test_table where username = $username");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_OBJ);
var_dump($row);

Expected result:
----------------
freetds debug log and MSSQL Profiler log is following
select * from test_table where username = '한글'

Actual result:
--------------
freetds debug log and MSSQL Profiler log is following
select * from test_table where username = 0x27ed959ceab88027

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-01 21:43 UTC] kir dot morozov at gmail dot com
I can confirm, no matter what was put to charset, encoding stays same,
 [2016-08-01 05:21 UTC] sungtae542 at gmail dot com
Ubuntu 16.04 + PHP7.0.8 PDO_dblib + parambind(UTF8) + mssql : Fail
Ubuntu 16.04 + PHP7.0.8 PDO_dblib + UTF8 query + mssql : OK

Only mssql + parambind + PHP7.0.x is broken 
mssql + parambind + PHP5.5.9 is working.
mssql + NO-parambind + PHP7.0.x is working. 
mysql + parambind + PHP7.0.x is working.

I check at freetds debug log and mssql query profiler.
 [2016-09-14 21:47 UTC] adambaratz@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: adambaratz
 [2016-09-14 21:47 UTC] adambaratz@php.net
This will be fixed with the next 7.0.x release:
https://github.com/php/php-src/commit/2302eef5c93b722d5311549dd59d495ff11d3b0d
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC