SQL Server stores a uniqueidentifier with mixed endianness. The first three groups (4, 2 and 2 bytes) are byte-reversed compared to the RFC 4122 layout; the last 8 bytes are unchanged. The library has three methods for this conversion.
| Method | Description |
|---|---|
Uuid::importFromSqlServer(string $sqlServerGuid): self |
SQL Server GUID string to a standard Uuid |
$uuid->toSqlServer(): string |
Uppercase GUID string in SQL Server byte order |
$uuid->toSqlServerBinary(): string |
16 bytes in SQL Server byte order |
Import from SQL Server
use Webpatser\Uuid\Uuid; $uuid = Uuid::importFromSqlServer('825B076B-44EC-E511-80DC-00155D0ABC54'); echo $uuid->string; // 6b075b82-ec44-11e5-80dc-00155d0abc54
Anything that does not contain 32 hex digits throws Exception('Invalid SQL Server GUID format.').
Export to SQL Server
$uuid = Uuid::import('6b075b82-ec44-11e5-80dc-00155d0abc54'); $sqlGuid = $uuid->toSqlServer(); // "825B076B-44EC-E511-80DC-00155D0ABC54"$sqlBin = $uuid->toSqlServerBinary(); // 16 bytes
Round trip
$original = Uuid::v4(); $back = Uuid::importFromSqlServer($original->toSqlServer()); Uuid::compare($original->string, $back->string); // true
Removed in 2.0.0
isSqlServerFormat() is gone. It only validated the string format and could not detect the byte order. See Upgrading from 1.x.