I'm using PDO to select from an MS SQL DB, but I get the same results when using mssql_connect(). Some of the fields containing GUIDs (e.g. "F6465061-8E9C-4EA2-9DFD-65B9598AA7FA") are outputting as gibberish, while the other fields come through just fine. Is this some kind of encoding issue? At the DB level, or in my querying?
The display is fine in NaviCat for SQL Server:
But when I run the same query with PHP, the output looks like this:
[0] => Array
(
[0] => ƒg C0³O™qúŠ˜M²
[1] => Michael Mizrachi
[2] => œÆ:²ùöL‚‹!hØåq?
[3] => Player
[4] => åBÐÜ·ÀjF‡æá:í%§
[5] => )ÛjÀÛ†‹E“l7åô
[6] => Jan 11 2008 06:13:54:657PM
[7] => Dec 28 2008 01:17:29:733PM
)
Here's my PHP code, in case it helps:
try {
$dbh = new PDO('dblib:host='.$sql_host.';dbname='.$sql_db, $sql_user, $sql_pw);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$query = file_get_contents("player.sql");
$stmt = $dbh->query($query);
do {
$rowset = $stmt->fetchAll(PDO::FETCH_NUM);
if ($rowset) {
print_r($rowset);
}
} while ($stmt->nextRowset());
Any ideas??
Here's a chunk of the SQL query:
BEGIN
DECLARE @id uniqueidentifier = '{18096783-3043-4FB3-9971-FA8A1A984DB2}';
DECLARE @version int;
SELECT
i.[ID]
,i.[Name]
,i.[TemplateID]
,t.[Name] as [TemplateName]
,i.[MasterID]
,i.[ParentID]
,i.[Created]
,i.[Updated]
FROM
[dbo].[Items] i (nolock)
JOIN
[dbo].[Items] t (nolock)
ON t.[ID] = i.[TemplateID]
WHERE
i.[ID] = @id
SELECT
@version = MAX(Version)
FROM
[dbo].[VersionedFields] (nolock)
WHERE
[ItemId] = @id