Re: equivalent to mysql_insert_id()
| From: | Davey | Date: | Thu, 01 Jul 2004 02:34:05 +0000 |
| Subject: | Re: equivalent to mysql_insert_id() | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13427@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
Vern T Takebayashi wrote:Assuming ids are sequential (as they are in MySQL's autoincrement) then the nextId() - 1 == last id used, this will hit snags when the last row inserted is removed however. - DaveyHi, Please excuse my ignorance as I just started looking at PEAR DB this past weekend. I have some PHP scripts that use the mysql_insert_id() function to return the last ID generated using auto_increment. In PEAR, is using the nextID() function and subtracting one, roughly equivalent to using the mysql_insert_id() function? I suppose that changing the code to use sequences might be better, but I was thinking that the short-term solution would be using the nextID() function in the manner described above.this should work: mysql_insert_id($db->connection) your solution is not portable anyways .. well your solution is portable across all rdbms that support autoincrement .. so it does have that advantage however substracting 1 makes no sense