douer9399 2019-03-13 16:46
浏览 107

将uniqueidentifier存储到php变量中,然后将变量作为uniqueidentifier插入

I have two different SQL Tables, both of them have an uniqueidentifier field called ID.

On my website, im calling a query to store into a variable the uniqueidentifier field from the table A.

$query = "SELECT ID FROM [dbo].[TableA] WHERE Name='{$name}'";
$result = sqlsrv_query($conn, $query);

while ($row = sqlsrv_fetch_array($result)){
    $ID= $row['ID'];
}   

Then, after storing this unique identifier into $ID, im inserting it into the TableB.

$query = "INSERT INTO [dbo].TableB(ID) values ('{$ID}')";
$result = sqlsrv_query($conn, $query); 

This will not work, showing the following error on sqlsrv_errors()

Syntax error, permission violation or other non-specific error.

The query works properly when we change $ID for newid(), but im looking towards inserting my own value rather than generating a new one.

The $ID echo shows this: D52A7C05-0399-4C82-8662-0F5731B4062C, which is exactly the same value that is currently stored into the TableA id.

Maybe when I am storing the uniqueidentifier on $ID its being converted into string, therefore not being a correct value to be inserted as uniqueidentifier?

FIXED: Found out that I had a very small syntax error on the query. Used var_dump($query); to figure it. Thanks @ADyson.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
    • ¥15 gdf格式的脑电数据如何处理matlab
    • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
    • ¥100 监控抖音用户作品更新可以微信公众号提醒
    • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
    • ¥70 2048小游戏毕设项目
    • ¥20 mysql架构,按照姓名分表