This repository has been archived by the owner on Oct 28, 2020. It is now read-only.
forked from trooney/PDODblibBundle
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved the non-UCS-2 character replacement to PDOStatement#bindValue
- Loading branch information
Roel Arents
committed
Jul 10, 2015
1 parent
11a78a8
commit 7ce8343
Showing
2 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Lsw\DoctrinePdoDblib\Doctrine\DBAL\Driver\PDODblib; | ||
|
||
class PDOStatement extends \Doctrine\DBAL\Driver\PDOStatement | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* Freetds communicates with the server using UCS-2 (since v7.0). | ||
* Freetds claims to convert from any given client charset to UCS-2 using iconv. Which should strip or replace unsupported chars. | ||
* However in my experience, characters like 👍 (THUMBS UP SIGN, \u1F44D) still end up in Sqlsrv shouting '102 incorrect syntax'. | ||
* Upon binding a value, this function replaces the unsupported characters. | ||
*/ | ||
public function bindValue($param, $value, $type = \PDO::PARAM_STR) | ||
{ | ||
if ($type == \PDO::PARAM_STR) { | ||
$value = static::replaceNonUcs2Chars($value); | ||
} | ||
return parent::bindValue($param, $value, $type); | ||
} | ||
|
||
/** | ||
* UCS-2 cannot represent Unicode code points outside the BMP. (> 16 bits.) | ||
* This function replaces those characters in a string with the REPLACEMENT CHARACTER. | ||
* @param string $val | ||
* @return string | ||
*/ | ||
public static function replaceNonUcs2Chars($val) | ||
{ | ||
return is_string($val) ? \preg_replace('/[^\x{0}-x{FFFF}]/u', "�", $val) : $val; | ||
} | ||
|
||
|
||
} |