|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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.. |
|
#3
|
|||
|
|||
|
RE: MSSQL and @@IDENTITY
If the table has an auto_increment filed try:
$db_id = mysql_insert_id($db); Steve |
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > MSSQL and @@IDENTITY |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|