Re: newid()

From: Date: Fri, 11 Aug 2000 18:26:02 +0000
Subject: Re: newid()
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-1977@lists.php.net to get a copy of this message
What does your query look like? It will work if you do something like this: $con = sybase_pconnect('server', 'user', 'password'); $query = "INSERT INTO foo (auto,text) VALUES(NULL, 'text') "; $query .= "SELECT @@IDENTITY "; $result = sybase_query($query, $con); while($row = sybase_fetch_row($result)) { newid = (integer) $row[0]; } // end of while sybase_fetch_row Steven Campbell Christopher Cheng wrote: > > It does not seem to work for ordinary SQL statements without using stored > procedures. Is there a way to get around with it? > > -----Original Message----- > From: scampbel [mailto:scampbel]On Behalf Of Steven Campbell > Sent: Friday, August 11, 2000 10:44 AM > To: chengcsw@netvigator.com > Cc: Mike Hanney; php-db@lists.php.net > Subject: Re: [PHP-DB] newid() > > SELECT @@IDENTITY executed after the INSERT statement will return the > last inserted identity on SQL Server. > > Steven Campbell > > Christopher Cheng wrote: > > > > By the way, I am using MS SQL Server 7.0. Do you know an equilvalent > > function in MS SQL Server? > > > > Thank you very much. > > > > -----Original Message----- > > From: Mike Hanney [mailto:mike@tradebasics.com] > > Sent: Friday, August 11, 2000 9:47 AM > > To: chengcsw@netvigator.com; php-db@lists.php.net > > Subject: Re: [PHP-DB] newid() > > > > Hi, > > > > You need to use something like LAST_INSERT_ID(), depending on what > database > > you're using (presumably MySQL). > > > > INSERT INTO foo (auto,text) VALUES(NULL,'text') > > INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text') > > > > I think the LAST_INSERT_ID() function will give you the most recent > > auto_increment key on a per connection basis not per thread. If anyone > > knows for sure please say. > > > > Mike. > > > > At 00:18 12/08/00 -0700, Christopher Cheng wrote: > > >My intention is to update the product table and the safety certificate > > table > > >associated with it. As I execute the SQL statement: > > >update products values (newid(), .....) > > >can I have the primary key generated by the newid() returned to my php > > >script? > > > > > > > > >-- > > >PHP Database Mailing List (http://www.php.net/) > > >To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > >For additional commands, e-mail: php-db-help@lists.php.net > > >To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > > PHP Database Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > > For additional commands, e-mail: php-db-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#1977) next »