|
|
|
|
|
|
| Author |
Message |
frizzle *nix forums Guru
Joined: 25 Mar 2005
Posts: 320
|
Posted: Fri Jul 21, 2006 9:48 am Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
Andy Hassall wrote:
| Quote: | 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
|
Wow! Thanks for the extensive information. I understand your
conclusion, but the rest is unfortunately just a load of jibberish (to
technical) to me ... :(
Frizzle. |
|
| Back to top |
|
 |
Andy Hassall *nix forums Guru
Joined: 20 Feb 2005
Posts: 874
|
Posted: Thu Jul 20, 2006 10:51 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
On 20 Jul 2006 14:36:19 -0700, "frizzle" <phpfrizzle@gmail.com> wrote:
| Quote: | 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 top |
|
 |
Jerry Stuckle *nix forums Guru
Joined: 24 Feb 2005
Posts: 1515
|
Posted: Thu Jul 20, 2006 10:11 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
frizzle wrote:
| Quote: | Jerry Stuckle wrote:
frizzle wrote:
Rik wrote:
Chris wrote:
I believe you're looking for mysql_last_insert_id()
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen this
one.
That's because mysql_last_insert_id() is not a PHP function. Frizzle was
unfortunately on the fritz. mysql_insert_id() it is, which should work
Grtz,
--
Rik Wasmus
I assume the result to be equal.
Would mysql_insert_id() still require a DB connection to be open?
Frizzle.
Yes, it's a MySQL call.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
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 ...
Frizzle
|
Yes, because it isn't returned so there's no cache to store it in.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
================== |
|
| Back to top |
|
 |
frizzle *nix forums Guru
Joined: 25 Mar 2005
Posts: 320
|
Posted: Thu Jul 20, 2006 9:36 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
Jerry Stuckle wrote:
| Quote: | frizzle wrote:
Rik wrote:
Chris wrote:
I believe you're looking for mysql_last_insert_id()
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen this
one.
That's because mysql_last_insert_id() is not a PHP function. Frizzle was
unfortunately on the fritz. mysql_insert_id() it is, which should work
Grtz,
--
Rik Wasmus
I assume the result to be equal.
Would mysql_insert_id() still require a DB connection to be open?
Frizzle.
Yes, it's a MySQL call.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|
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 ...
Frizzle |
|
| Back to top |
|
 |
Jerry Stuckle *nix forums Guru
Joined: 24 Feb 2005
Posts: 1515
|
Posted: Thu Jul 20, 2006 9:18 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
frizzle wrote:
| Quote: | Rik wrote:
Chris wrote:
I believe you're looking for mysql_last_insert_id()
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen this
one.
That's because mysql_last_insert_id() is not a PHP function. Frizzle was
unfortunately on the fritz. mysql_insert_id() it is, which should work
Grtz,
--
Rik Wasmus
I assume the result to be equal.
Would mysql_insert_id() still require a DB connection to be open?
Frizzle.
|
Yes, it's a MySQL call.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
================== |
|
| Back to top |
|
 |
Rik *nix forums Guru Wannabe
Joined: 16 Nov 2005
Posts: 291
|
Posted: Thu Jul 20, 2006 8:54 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
frizzle wrote:
| Quote: | Rik wrote:
Chris wrote:
I believe you're looking for mysql_last_insert_id()
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen
this one.
That's because mysql_last_insert_id() is not a PHP function. Frizzle
was unfortunately on the fritz. mysql_insert_id() it is, which
should work
Grtz,
--
Rik Wasmus
I assume the result to be equal.
Would mysql_insert_id() still require a DB connection to be open?
|
Yes. It's result isn't cached after a query in PHP, but queried from the
database itself.
Grtz,
--
Rik Wasmus |
|
| Back to top |
|
 |
frizzle *nix forums Guru
Joined: 25 Mar 2005
Posts: 320
|
Posted: Thu Jul 20, 2006 6:12 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
Rik wrote:
| Quote: | Chris wrote:
I believe you're looking for mysql_last_insert_id()
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen this
one.
That's because mysql_last_insert_id() is not a PHP function. Frizzle was
unfortunately on the fritz. mysql_insert_id() it is, which should work
Grtz,
--
Rik Wasmus
|
I assume the result to be equal.
Would mysql_insert_id() still require a DB connection to be open?
Frizzle. |
|
| Back to top |
|
 |
Rik *nix forums Guru Wannabe
Joined: 16 Nov 2005
Posts: 291
|
Posted: Tue Jul 18, 2006 6:27 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
Chris wrote:
| Quote: | I believe you're looking for mysql_last_insert_id()
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen this
one.
|
That's because mysql_last_insert_id() is not a PHP function. Frizzle was
unfortunately on the fritz. mysql_insert_id() it is, which should work
Grtz,
--
Rik Wasmus |
|
| Back to top |
|
 |
Chris *nix forums beginner
Joined: 24 May 2006
Posts: 13
|
Posted: Tue Jul 18, 2006 3:58 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
Thanks - that makes sense, I'll give it a try. Hard to find all the
built-in functions - I had seen mysql_insert_id, but hadn't seen this one.
"frizzle" <phpfrizzle@gmail.com> wrote in message
news:1153172829.748180.313090@m79g2000cwm.googlegroups.com...
| Quote: |
I believe you're looking for mysql_last_insert_id()
Frizzle.
|
|
|
| Back to top |
|
 |
frizzle *nix forums Guru
Joined: 25 Mar 2005
Posts: 320
|
Posted: Mon Jul 17, 2006 9:47 pm Post subject:
Re: acquiring value of primary key from uploaded file
|
|
|
Chris wrote:
| Quote: | I have a PHP file upload feature that also gives the user the option to
assign more than 1 project association to the file. The file's name, title,
primary project, etc. is inserted into a document link table in a MySQL db
after the file is uploaded. The secondary (and multiple) project(s) are also
selected using a separate list box (there are 2 boxes - one for the primary
project, and one for any/all associated projects) The selected values from
the secondary box need to be inserted into a junction table that reflects
both the id for the newly uploaded file and the secondary project(s) - with
a primary key for the association itself, i.e,:
assoc_id doc_id proj_id
1 265 5
2 265 3
3 265 1
I would use a foreach statement to pull the projects from the select list,
but how do I get the newly generated doc_id in order to pass that value to
the association table? Can I assign it a variable at the same time I insert
the data into the primary table? The ID is auto-incremented and is inserted
into the primary table as follows:
$tool_insert = "INSERT INTO tools VALUES ('', '$uploadedname', '$tooltitle',
'$tooldesc', '$tooltype_id', '$toolcat_id', '$primeproj_id', '$location')";
Thanks for any help.
Christina
|
I believe you're looking for mysql_last_insert_id()
Frizzle. |
|
| Back to top |
|
 |
Chris *nix forums beginner
Joined: 24 May 2006
Posts: 13
|
Posted: Mon Jul 17, 2006 9:32 pm Post subject:
acquiring value of primary key from uploaded file
|
|
|
I have a PHP file upload feature that also gives the user the option to
assign more than 1 project association to the file. The file's name, title,
primary project, etc. is inserted into a document link table in a MySQL db
after the file is uploaded. The secondary (and multiple) project(s) are also
selected using a separate list box (there are 2 boxes - one for the primary
project, and one for any/all associated projects) The selected values from
the secondary box need to be inserted into a junction table that reflects
both the id for the newly uploaded file and the secondary project(s) - with
a primary key for the association itself, i.e,:
assoc_id doc_id proj_id
1 265 5
2 265 3
3 265 1
I would use a foreach statement to pull the projects from the select list,
but how do I get the newly generated doc_id in order to pass that value to
the association table? Can I assign it a variable at the same time I insert
the data into the primary table? The ID is auto-incremented and is inserted
into the primary table as follows:
$tool_insert = "INSERT INTO tools VALUES ('', '$uploadedname', '$tooltitle',
'$tooldesc', '$tooltype_id', '$toolcat_id', '$primeproj_id', '$location')";
Thanks for any help.
Christina |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Fri Nov 21, 2008 10:42 pm | All times are GMT
|
|
Loans | Loans | Mortgage | Loans | Budapest
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|