RE: [PHP] RE: non-auto increment question
| From: | Jerry Schwartz | Date: | Thu, 26 Feb 2009 21:00:00 +0000 |
| Subject: | RE: [PHP] RE: non-auto increment question | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288864@lists.php.net to get a copy of this message | ||
Sorry, I should know better.
>-----Original Message-----
>From: Ashley Sheridan [mailto:ash@ashleysheridan.co.uk]
>Sent: Thursday, February 26, 2009 1:51 PM
>To: Jerry Schwartz
>Cc: 'PJ'; 'Gary W. Smith'; 'MySql'; php-general@lists.php.net
>Subject: RE: [PHP] RE: non-auto increment question
>
>On Thu, 2009-02-26 at 13:44 -0500, Jerry Schwartz wrote:
>> >Here's how I mostly do it (albeit simplified):
>> >
>> >$query = "INSERT INTO
>> >
sometable(title,content)
>> >VALUES('$title','$content')";
>> >$result = mysql_query($query);
>> >$autoId = mysql_insert_id($result);
>> >
>> >$query = "INSERT INTO £¡9ÿ%H5
>> >ÀZ*—ÛÖanother_table(link_id,value)
>> >VALUES($autoId,'$value');
>> >$result = mysql_query($query);
>> >
>> >No need to call another query to retrieve the last inserted id, as it
>is
>> >tied to the last query executed within this session.
>> >
>> >
>> >Ash
>> >www.ashleysheridan.co.uk
>>
>> [JS] Ashley is absolutely right, I'd forgotten about the
>mysql_insert_id
>> shorthand. (I'm a one-man band, and for the last week or two I've been
>> immersed in VB for Access forms.) Not only is she right, but her way
>is
>> better. Presumably a language's internal code is maintained as the
>specific
>> database changes. You can make yourself more independent of the
>specific
>> database by using the PDO abstraction, although I would save that for
>a
>> rainy weekend.
>>
>> Regards,
>>
>> Jerry Schwartz
>> The Infoshop by Global Information Incorporated
>> 195 Farmington Ave.
>> Farmington, CT 06032
>>
>> 860.674.8796 / FAX: 860.674.8341
>>
>> www.the-infoshop.com
>> www.giiexpress.com
>> www.etudes-marche.com
>>
>>
>>
>>
>>
>>
>>
>I just checked, and yep, I'm definitely still a he ;)
>
>
>Ash
>www.ashleysheridan.co.uk