Reply to Re: acquiring value of primary key from uploaded file

Your name:

Reply:


Posted by Andy Hassall on 12/17/89 11:53

On 20 Jul 2006 14:36:19 -0700, "frizzle" <phpfrizzle@gmail.com> wrote:

>>> I assume the result to be equal.
>>> Would mysql_insert_id() still require a DB connection to be open?
>>
>> Yes, it's a MySQL call.
>
>So you'd have to run another extra call to the database, instead of
>getting it from cache ?
>Wouldn't that make it slower?
>Not quite getting this, but liked to know how it works ...

Interesting question, as the docs don't seem to explicitly state whether it
does or does not.

Tracing network traffic with Ethereal, MySQL client 5.0.22, server version
4.1.7 on another machine, and sleep() calls between each step to make it
obvious what is happening at each stage, shows that calling mysql_insert_id()
does not result in any communication with the server; so the value must be sent
across and stored in the client as part of running the previous mysql_query().

Looking at the individual packets, this is indeed the case; the ID is returned
as part of the payload in the "OK" packet in reply to the query:


No. Time Source Destination Protocol Info
12 0.006948 192.168.1.101 192.168.1.100 MySQL Request
Command: Query : insert into t (id) values (null)

Frame 12 (91 bytes on wire, 91 bytes captured)
Ethernet II, Src: SC&C_d5:81:1c (00:00:21:d5:81:1c), Dst: SC&C_d5:81:1a
(00:00:21:d5:81:1a)
Internet Protocol, Src: 192.168.1.101 (192.168.1.101), Dst: 192.168.1.100
(192.168.1.100)
Transmission Control Protocol, Src Port: 3693 (3693), Dst Port: 3306 (3306),
Seq: 86, Ack: 83, Len: 37
MySQL Protocol
Packet Length: 33
Packet Number: 0
Command
Command: Query (3)
Parameter: insert into t (id) values (null)

No. Time Source Destination Protocol Info
13 0.008511 192.168.1.100 192.168.1.101 MySQL Response
OK

Frame 13 (65 bytes on wire, 65 bytes captured)
Ethernet II, Src: SC&C_d5:81:1a (00:00:21:d5:81:1a), Dst: SC&C_d5:81:1c
(00:00:21:d5:81:1c)
Internet Protocol, Src: 192.168.1.100 (192.168.1.100), Dst: 192.168.1.101
(192.168.1.101)
Transmission Control Protocol, Src Port: 3306 (3306), Dst Port: 3693 (3693),
Seq: 83, Ack: 123, Len: 11
MySQL Protocol
Packet Length: 7
Packet Number: 1
Response Code: 0
Payload: \001\017\002


In this case the ID was 15 - which is octal \017 - the middle byte in the
payload of the response to the query.

--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация