Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old July 4th, 2002, 01:01 PM
Cassidy Cassidy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 Cassidy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MSSQL and @@IDENTITY

I have PHP running on a linux box, connecting to an MS SQL database using the freetds library. Everything works fine, except when I want to extract the last insert id from a newly inserted row.

I try to use both "SELECT @@IDENTITY" and "SELECT IDENT_CURRENT('tablename'). The return value i get is usually 37 digit negative integer number (which is way of from the real value). The same thing happens when I use the command line tool that is included with freetds(tsql). Doing the same operations from the Query analyzer in MS SQL works fine though.

I have searched through google, and the docs in the online commented version of the PHP documentation, but I don't find anyone with the same problem. I am using MS SQL 7.0 evaluation version.

Reply With Quote
  #2  
Old July 14th, 2002, 01:24 PM
CmdrDats CmdrDats is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: <br><img src='http://www.dats.co.za/icon.gif'>
Posts: 269 CmdrDats User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to CmdrDats Send a message via AIM to CmdrDats Send a message via Yahoo to CmdrDats
RE: MSSQL and @@IDENTITY

I think i've had the same problem & what i've done to counter it is simply run the query "SELECT max(id) as id FROM table" straight afterward.

Admittedly, this is a pretty lame solution, since if the id's get mixed somehow or if somebody does another insert query right after yours and before the max(id) one, max(id) might give you the wrong one..

Chances are slim though since in most systems, inserts where you need the id don't happen fast and furiously..

Reply With Quote
  #3  
Old August 14th, 2002, 01:54 PM
ssmith1227 ssmith1227 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Tampa, FL
Posts: 8 ssmith1227 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: MSSQL and @@IDENTITY

If the table has an auto_increment filed try:

$db_id = mysql_insert_id($db);

Steve

Reply With Quote
  #4  
Old August 21st, 2002, 10:44 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: MSSQL and @@IDENTITY

hi everyone,
i gather you all were successfully able to connect the MS SQL database to php on a linux box.
i have the same problem. i dotn knwo how to connect. can you guys please guide me on how to do it...
i too have MS SQL datbase and php on a linux box.
thanks a ton

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > MSSQL and @@IDENTITY


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway