views:

238

answers:

1

I've been tasked with getting two MS SQL based products to synchronize. My predecessor was content to match records based on a combination of name and address, but both systems have a GUID, and only one is actually using it. So my thought was to match up my existing records and copy the GUID from one database to the other. But I can't seem to update a GUID in MS SQL using PHP and ODBC. The query fails silently. If I echo the query and copy/paste it into SQL Management Studio or Oracle SQL Developer, it works fine. The simplified version of my query looks like this:

$SQL = "UPDATE Contact SET SifGuid = CONVERT(VARCHAR(36), '" . $this->GUID . "') ";
$SQL .= "WHERE contactID = " . $this->POSID . ";

Sending that query through odbc_exec fails. But like I mentioned, the same exact query works fine in SQL Management Studio or Oracle SQL Developer.

Any ideas?

Thanks in advance!

A: 

When you query the data out of the first server, be sure you are converting the data to VARCHAR()

SELECT CONVERT(VARCHAR(36),guidCol) AS guid FROM table 

Then when you insert, you need to cast it back to a GUID value since it's already a string in PHP.

UPDATE table SET guidCol = CAST(UNIQUEIDENTIFIER, '" . $this->GUID . "') 
Erik Giberti
Thanks, Erik, but no dice. Still won't work through odbc_exec, although odbc_error isn't showing anything wrong. But if I copy the query into SQL Developer, it executes just fine.
bradrhine