开发者

How to update GUID in MS SQL via PHP/ODBC?

I've been tasked with getting two MS SQL based products to synchronize. My predec开发者_JAVA技巧essor 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!


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 . "') 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜