Jump to content


Check out our Community Blogs

djnos14

Member Since 13 Apr 2010
Offline Last Active Apr 13 2010 07:44 AM
-----

Posts I've Made

In Topic: PHP, MSSQL 200, ntext/nvarchar

13 April 2010 - 07:44 AM

Hi !

I put my comment too late I think but if my answer can ever help you and others...
I was in front of the same mater and i resolved it like this :

//retrieve a PDO handler instance
$dbHd=Tools_Data_PDOBridge::getInstance(Tools_Data_PDOBridge::PDO_MSSQL, 'server', 'db', 'user', 'pwd');
$srcStr='éè$^^Ɇ';
$dataToInsert=mb_convert_encoding($srcStr, 'UCS-2LE', 'UTF-8');
$arr = unpack('H*hex', $dataToInsert);

var_dump($arr);

$hex = "0x{$arr['hex']}";
$str='insert into CIVILITE(CIV_LIBELLE, test) values(\''.mb_convert_encoding('éè$^^É', 'ISO-8859-1', 'UTF-8').'\', '.$hex.');';
$dbHd->exec($str);

echo $srcStr.PHP_EOL;

$st=$dbHd->query('select top 1 convert(varbinary(200), test) as test from CIVILITE where CIV_ID>3;');

$civ=$st->fetch(PDO::FETCH_ASSOC);

var_dump($civ['test']);

$rtData=pack('H*', $civ['test']);
echo iconv('UCS-2LE', 'UTF-8', $rtData);


Bye! :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download