1--TEST-- 2PDO_DBLIB: Uniqueidentifier column data type stringifying 3--EXTENSIONS-- 4pdo_dblib 5--SKIPIF-- 6<?php 7require __DIR__ . '/config.inc'; 8if (in_array($db->getAttribute(PDO::DBLIB_ATTR_TDS_VERSION), ['4.2', '4.6'])) die('skip feature unsupported by this TDS version'); 9?> 10--FILE-- 11<?php 12require __DIR__ . '/config.inc'; 13 14 15$testGUID = '82A88958-672B-4C22-842F-216E2B88E72A'; 16$testGUIDBinary = base64_decode('WImogitnIkyELyFuK4jnKg=='); 17 18$sql = "SELECT CAST('$testGUID' as uniqueidentifier) as [guid]"; 19 20//-------------------------------------------------------------------------------- 21// 1. Get and Set the attribute 22//-------------------------------------------------------------------------------- 23$db->setAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true); 24var_dump(true === $db->getAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER)); 25$db->setAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, false); 26var_dump(false === $db->getAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER)); 27 28 29//-------------------------------------------------------------------------------- 30// 2. Binary 31//-------------------------------------------------------------------------------- 32$stmt = $db->query($sql); 33$row = $stmt->fetch(PDO::FETCH_ASSOC); 34 35var_dump($row['guid'] === $testGUIDBinary); 36 37 38//-------------------------------------------------------------------------------- 39// 3. PDO::ATTR_STRINGIFY_FETCHES must not affect `uniqueidentifier` representation 40//-------------------------------------------------------------------------------- 41$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true); 42$stmt = $db->query($sql); 43$row = $stmt->fetch(PDO::FETCH_ASSOC); 44$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); 45 46var_dump($row['guid'] === $testGUIDBinary); 47 48 49//-------------------------------------------------------------------------------- 50// 4. Stringifying 51// ! With TDS protocol version <7.0 binary will be returned and the test will fail ! 52// TODO: something from PDO::ATTR_SERVER_VERSION, PDO::ATTR_CLIENT_VERSION or PDO::ATTR_SERVER_INFO should be used 53// to get TDS version and skip this test in this case. 54//-------------------------------------------------------------------------------- 55$db->setAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true); 56$stmt = $db->query($sql); 57$row = $stmt->fetch(PDO::FETCH_ASSOC); 58 59var_dump($row['guid'] === $testGUID); 60var_dump($row['guid']); 61 62?> 63--EXPECT-- 64bool(true) 65bool(true) 66bool(true) 67bool(true) 68bool(true) 69string(36) "82A88958-672B-4C22-842F-216E2B88E72A" 70