dongxia2068 2013-09-05 13:43
浏览 186

php - sql server:“set identity_insert on”无效

I'm currently working on php application, with sql server database. I'm using the sqlsrv driver in php to make queries on my DB.

The problem is that I have to make an insert on a field which has Identity Specification. I tried to use instruction "SET IDENTITY_INSERT tableName ON", but it looks like it doesn't work with sqlsrv_query...

Does anyone know how to solve this problem?

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzhi3454 2013-09-05 14:27
    关注

    Did you call command in a batch by itself and then perform the insert?

    See MSDN on SET IDENTITY_INSERT ON/OFF, it uses to GO to commit the batch before doing the insert.

    Here is the reference manual for PHP SQLSVR.

    When I was writing VB script or C# in the past, I would use query() to return a result set. The client side code uses a cursor to work with the data.strong text

    However, this statement should be executed thru the execute() command.

    Try the following.

    1 - execute() - IDENTITY ON
    2 - execute() - INSERT (S)
    3 - execute() - IDENTITY OFF

    See if that fixes your issue.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器