Re: [PHP] mysql_insert_id() vs LAST_INSERT_ID()

2002-02-07 Thread Jason Wong

On Thursday 07 February 2002 23:08, Erik Price wrote:
 I have two questions:

I think the php-db list is more appropriate for these.

 1. Can anyone tell me whether the following statement is true or false?
 The PHP function mysql_insert_id() differs from the MySQL function
 LAST_INSERT_ID() in that the PHP function returns the last
 auto-incremented value from the current connection, and the MySQL
 function returns the highest current value in a table's AUTO_INCREMENT
 column.

IIRC they both serve the same function. 

 2. Secondly, if anyone could answer the following question it would be
 very helpful...
 When updating a foreign key (in-between table for many-to-many
 relationships) using the last auto-incremented value, is it better to
 write several separate SQL queries and store them in the same variable
 for mysql_query(), or is it better to write several separate SQL queries
 and store them in separate variables, and then run separate
 mysql_query() functions against those variables separately?


[snip]


 In other words, when performing multiple SQL queries simultaneously, is
 it better to give them their own variable (each SQL statement), or can
 you lump them all together?

I don't think MySQL is able to handle multiple queries in one statement. IOW 
you would have to perform each separately.


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
When childhood dies, its corpses are called adults.
-- Brian Aldiss
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] mysql_insert_id?

2002-01-16 Thread mike cullerton

on 1/16/02 7:42 AM, Martin Wickman at [EMAIL PROTECTED] wrote:

 Dl Neil wrote:
 
 2 because the (function argument) controlling feature is the connection, it
 is not possible for another
 concurrent user to 'steal' your ID or influence the ID returned to you - it's
 all yours!
 
 Ok, assume you are correct, but what if you are using persistent
 connections (ie pconnet)?
 

it's still 'your' persistent connection that's being queried though. from
the manual on mysql_pconnect

 Returns a positive MySQL persistent link identifier on success

this is why you use the link identifier in things like mysql_query, and lets
mysql 'know' what 'your' last insert was.

hope this helps,
mike

 -- mike cullerton   michaelc at cullerton dot com



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread Jimmy

Hi Martin,

 2 because the (function argument) controlling feature is the
 connection, it is not possible for another concurrent user to
 'steal' your ID or influence the ID returned to you - it's all

 Ok, assume you are correct, but what if you are using persistent 
 connections (ie pconnet)?

don't worry, persistent connection is per-child-process basis,
so concurrent users will use different connection to DB.

the only problem i can think of might occur with pconnect is,
last_insert_id() will return you the last inserted ID from
previous 'session', not current 'session'.
to prevent this, you should call last_insert_id() only when
your INSERT query executed succesfully.


--
Jimmy

Right thinking leads to right living



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: [PHP-DB] Re: [PHP] mysql_insert_id?

2002-01-16 Thread DL Neil

Hi Martin,

  2 because the (function argument) controlling feature is the connection, it is not 
possible for another
  concurrent user to 'steal' your ID or influence the ID returned to you - it's all 
yours!

 Ok, assume you are correct, but what if you are using persistent
 connections (ie pconnet)?

=According to the manual (Chapter 22. Persistent Database Connections) there is no 
difference in functionality
between persistent and non-persistent connections (only a (possible) difference in 
efficiency/response time).
Thus use of persistence does not buy you into other issues.

=If I leave it there, you're going to come back with another question, aren't you!?

=This is my understanding. A connection is set up to enable communication between the 
PHP script and the RDBMS.
The connection is exclusive to the script and only lasts the life of the script. Now 
let's look at the word
script. Each user/browser is processed within the (Apache) web server as a separate 
child process. If the
process calls for PHP processing, then what happens in one process within the web 
server is kept quite separate
from what's happening in another process. This applies even if they both use PHP, and 
even if they are both
running the same PHP script, and even against the same MySQL db/tbl, ie because of the 
way Apache works, there
is no 'sharing' of connections/cleverness in a bid for extra 'efficiency'.

=Thus there is no way for my (connection) use of the db to interfere with your 
(separate connection) use of the
same, in terms of AUTO_INCREMENT, INSERT IDs, and suchlike.

=I'd really like to hear from someone who can talk more authoritatively on the subject 
though!

=Regards,
=dn



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread DL Neil

Hi Jimmy,

  2 because the (function argument) controlling feature is the
  connection, it is not possible for another concurrent user to
  'steal' your ID or influence the ID returned to you - it's all

  Ok, assume you are correct, but what if you are using persistent
  connections (ie pconnet)?

 don't worry, persistent connection is per-child-process basis,
 so concurrent users will use different connection to DB.

 the only problem i can think of might occur with pconnect is,
 last_insert_id() will return you the last inserted ID from
 previous 'session', not current 'session'.
 to prevent this, you should call last_insert_id() only when
 your INSERT query executed succesfully.

=Of course a right-living boy like me, cannot conceive of why one would look up 
LAST_INSERT other than
immediately after the INSERT/UPDATE command...

=However this is an interesting thought and you are right. There are differences 
between the MySQL
LAST_INSERT_ID and the PHP MySQL_

=The MySQL manual (6.3.6.2  Miscellaneous Functions) talks about Returns the last 
automatically generated value
that was inserted into an AUTO_INCREMENT column...The last ID that was generated is 
maintained in the server on
a per-connection basis., and a number of other if-s, but-s, and maybe-s that will get 
everyone going.

=(However I believe it also answer's Martin's question!)

=What I have noted is that the PHP manual 
(http://www.php.net/manual/en/function.mysql-insert-id.php) works
slightly differently (and possibly more simply), as well as emphasising the 
immediately after relationship
between this call and the preceding INSERT. An interesting point here and that is that 
it takes care of Jimmy's
concern: what happens if the INSERT query was successful.

=I think I prefer the PHP approach - and it is probably more efficient/quicker (from 
PHP) too.

=Further thoughts?
=dn



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread Jimmy

Hi DL,

 the only problem i can think of might occur with pconnect is,
 last_insert_id() will return you the last inserted ID from
 previous 'session', not current 'session'.
 to prevent this, you should call last_insert_id() only when
 your INSERT query executed succesfully.

 =Of course a right-living boy like me, cannot conceive of why one would
 look up LAST_INSERT other than immediately after the INSERT/UPDATE command...

calling last_insert_id() after INSERT is the number one rule
of course :)
What i mean was, what if the INSERT query fail, but the script still
execute the last_insert_id() function?
Most probably the returned value would be wrong, because it will
return the last_insert_id of previous INSERT query (from previous
'session')

 =What I have noted is that the PHP manual
 (http://www.php.net/manual/en/function.mysql-insert-id.php) works
 slightly differently (and possibly more simply), as well as
 emphasising the immediately after relationship between this call
 and the preceding INSERT.

I might be wrong, but i think PHP's mysql_insert_id() must be using
MySQL's API function call.
Meaning, it will return whatever value MySQL return.
Or in other word, mysql_insert_id() and last_insert_id() will return
the same result.

I have look thru the manual link above, and i think the phrase
immediately after in the manual is more to advise the user to do
mysql_insert_id() immediately after the INSERT query,
because last_insert_id value might get overwritten by the newest one.

the immediately after phares in the manual doesn't mean that PHP's
mysql_insert_id() function is somehow tied to the previous/last
INSERT query, so that if the INSERT fails then mysql_insert_id()
will intelegently return the correct value.

just my 1 cent

--
Jimmy

The average woman would rather have beauty than brains, because the average man can 
see better than he can think.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread mike cullerton

on 1/16/02 10:47 AM, Jimmy at [EMAIL PROTECTED] wrote:

 Hi DL,
 
 the only problem i can think of might occur with pconnect is,
 last_insert_id() will return you the last inserted ID from
 previous 'session', not current 'session'.
 to prevent this, you should call last_insert_id() only when
 your INSERT query executed succesfully.
 
 =Of course a right-living boy like me, cannot conceive of why one would
 look up LAST_INSERT other than immediately after the INSERT/UPDATE command...
 
 calling last_insert_id() after INSERT is the number one rule
 of course :)
 What i mean was, what if the INSERT query fail, but the script still
 execute the last_insert_id() function?
 Most probably the returned value would be wrong, because it will
 return the last_insert_id of previous INSERT query (from previous
 'session')

but of course, you'd have checked that the result id returned a valid result
and not an error in this case and never looked for the last_insert_id,
right?

;)
mike

 -- mike cullerton   michaelc at cullerton dot com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread Jimmy

Hi mike,

 last_insert_id() will return you the last inserted ID from
 previous 'session', not current 'session'.
 to prevent this, you should call last_insert_id() only when
 your INSERT query executed succesfully.

 Most probably the returned value would be wrong, because it will
 return the last_insert_id of previous INSERT query (from previous
 'session')

 but of course, you'd have checked that the result id returned a valid result
 and not an error in this case and never looked for the last_insert_id,

Exactly.
That's why in the first posting (read the first paragraph above),
I told him to exec last_insert_id() or mysql_insert_id() ONLY when
the insert query is SUCCESSFUL.

--
Jimmy

When you lose, don't lose the lesson.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread DL Neil

Hi Jimmy,

  the only problem i can think of might occur with pconnect is,
  last_insert_id() will return you the last inserted ID from
  previous 'session', not current 'session'.
  to prevent this, you should call last_insert_id() only when
  your INSERT query executed succesfully.
  =Of course a right-living boy like me, cannot conceive of why one would
  look up LAST_INSERT other than immediately after the INSERT/UPDATE command...
 calling last_insert_id() after INSERT is the number one rule
 of course :)
 What i mean was, what if the INSERT query fail, but the script still
 execute the last_insert_id() function?
 Most probably the returned value would be wrong, because it will
 return the last_insert_id of previous INSERT query (from previous
 'session')

=right living was a (poor) joke following your previous post's .SIG file 
aphorism...not a criticism. Now that
you have mentioned the possibility, I can imagine the odd (very odd) use for 
collecting an ID from a preceding
interraction (with the database).

=session is not the correct word/its use is potentially confusing (perhaps that's 
why it's in quotes?) -
persistence refers to the continuing connection between PHP and MySQL.

  =What I have noted is that the PHP manual
  (http://www.php.net/manual/en/function.mysql-insert-id.php) works
  slightly differently (and possibly more simply), as well as
  emphasising the immediately after relationship between this call
  and the preceding INSERT.

 I might be wrong, but i think PHP's mysql_insert_id() must be using
 MySQL's API function call.
 Meaning, it will return whatever value MySQL return.
 Or in other word, mysql_insert_id() and last_insert_id() will return
 the same result.

 I have look thru the manual link above, and i think the phrase
 immediately after in the manual is more to advise the user to do
 mysql_insert_id() immediately after the INSERT query,
 because last_insert_id value might get overwritten by the newest one.

 the immediately after phares in the manual doesn't mean that PHP's
 mysql_insert_id() function is somehow tied to the previous/last
 INSERT query, so that if the INSERT fails then mysql_insert_id()
 will intelegently return the correct value.

 just my 1 cent

=Agreed it would seem perfectly logical that the PHP function simply calls the MySQL 
source function. However it
is also possible that in order to save time the LAST_ID information is built into the 
resultset coming back from
the INSERT - thus when mysql_insert_id() is called PHP would not need to go back to 
MySQL/last_insert_id(). On
the other hand, the apparent differences between the two manuals may simply be in the 
expression of two
authors... I don't know [but would welcome competent advice!]

=the immediate advice is transparently logical best practice.

=I'm not sure that I've understood your last point. The comparison/difference, as I 
read/understood it, is that
if the INSERT works then both functions will operate correctly. However if the INSERT 
fails, then MySQL's
last_insert_id() will return the ID of the last record successfully inserted during 
the connection (whenever
that was) - without necessarily any recognition of an immediately preceding failure. 
Whereas PHP's
mysql_insert_id() is keyed to the resource identifier and returns zero if the 
**latest** INSERT failed for some
reason (and the rationale for my earlier comments/comparison).

=My thinking is that the PHP rationale makes the most/safest sense to me, and if I'm 
'in' PHP it seems best to
stick with that 'mode' than to go 'out' to MySQL to find the 'same' answer.

=Intriguing stuff,
=dn


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread Jimmy

Hi DL,

 =session is not the correct word/its use is potentially confusing
 (perhaps that's why it's in quotes?) - persistence refers to the
 continuing connection between PHP and MySQL.

yup, you're right.
session is not the correct word, but i can't find the
correct/easy word to subtitute session, so i just use session
but put it inside quotes :)

 However it is also possible that in order to save time the LAST_ID
 information is built into the resultset coming back from the INSERT -
 thus when mysql_insert_id() is called PHP would not need to go back
 to MySQL/last_insert_id().

yes, what you said could be true also.

Well, there's only one way to be sure how mysql_insert_id() works...read
the source code of PHP :) but unfortunately I dont have the source code,
and even if I do, I won't read it, because I am lousy at reading someone's
code...:)

nice discussion, Neil :)

--
Jimmy

Buy Land. They've stopped making it.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-16 Thread DL Neil

Jimmy,


  However it is also possible that in order to save time the LAST_ID
  information is built into the resultset coming back from the INSERT -
  thus when mysql_insert_id() is called PHP would not need to go back
  to MySQL/last_insert_id().

 yes, what you said could be true also.

 Well, there's only one way to be sure how mysql_insert_id() works...read
 the source code of PHP :) but unfortunately I dont have the source code,
 and even if I do, I won't read it, because I am lousy at reading someone's
 code...:)

=or run a script to perform an INSERT, then pause, eg go to a form, and whilst 
nothing's happening take the
MySQL server offline, then restart the script by returning from the form, and execute 
the call...

=I can't do this because my portable runs everything on one box (dev and prod and...).

 nice discussion, Neil :)

=thinking that stretches the mind!
=dn


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-15 Thread DL Neil

Hi Wee,

 Is it possible that I would get the wrong ID (Not the ID I just inserted in
 Auto_Increment field) by using mysql_insert_id function if someone is also
 inserting record at the same time? How does mysql_insert_id work accurately?


=A couple of things here:

1 if the field is defined as Auto_Increment then YOU will not insert an ID. Leave 
the field out of the INSERT
statement or transfer NULL, and MySQL will insert the correct ID value according to 
the 'increment' policy.

The construction of the mysql_insert_id() looks like this:
$AutoIncrementId = mysql_insert_id( $MySQLConnection );
Note that the function argument is the connection to MySQL (not the db/tbl !). Thus 
the ID is a by-product of
the connection (and the most recent INSERT it handled) - re-read the appropriate page 
in the manual for more
information, if required.

2 because the (function argument) controlling feature is the connection, it is not 
possible for another
concurrent user to 'steal' your ID or influence the ID returned to you - it's all 
yours!

The only way to get the wrong ID is to perform two IDs and then (vainly) try to get 
hold of the previous ID -
only the latest ID is available.

Clear now?
=dn




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id?

2002-01-15 Thread DL Neil

Hi Wee,

 Is it possible that I would get the wrong ID (Not the ID I just inserted in
 Auto_Increment field) by using mysql_insert_id function if someone is also
 inserting record at the same time? How does mysql_insert_id work accurately?


=A couple of things here:

1 if the field is defined as Auto_Increment then YOU will not insert an ID. Leave 
the field out of the INSERT
statement or transfer NULL, and MySQL will insert the correct ID value according to 
the 'increment' policy.

The construction of the mysql_insert_id() looks like this:

$AutoIncrementId = mysql_insert_id( $MySQLConnection );

Note that the function argument is the connection to MySQL (not the db/tbl !). Thus 
the ID is a by-product of
the connection (and the most recent INSERT it handled) - re-read the appropriate page 
in the manual for more
information, if required.

2 because the (function argument) controlling feature is the connection, it is not 
possible for another
concurrent user to 'steal' your ID or influence the ID returned to you - it's all 
yours!

The only way to get the wrong ID is to perform two IDs and then (vainly) try to get 
hold of the previous ID -
only the latest ID is available.

Clear now?
=dn





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id. need help!

2001-08-29 Thread Moax Tech List

post your code.

- Original Message -
From: lizlynch [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, August 29, 2001 4:32 AM
Subject: [PHP] mysql_insert_id. need help!


hi,

i have three tables:
customer
username
classification

the user will enter my web site enter the relevant customer details (which
are transfered to the database) (s)he will then enter their prefered
username, password and a password hint (again all sent to the database).
once they are registered they choose between three classification types.
i have used the mysql_insert_id () to obtain the customer_id from the
customer table and to insert it into the username table, however i also need
to insert it into the classification table but all i keep getting is 0.
can anyone advise, is it possible?

liz lynch



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id()

2001-07-07 Thread Chris Lambert - WhiteCrown Networks

I've used integer on many occasions with auto_increment, and have had no
problems. mysql_insert_id() returns the unique identifyer of the last record
inserted with mysql_query(). I'm not sure what MySQL function you're
referencing as an alternative, but you should be fine with an
integer/auto_increment/insert_id()...

/* Chris Lambert, CTO - [EMAIL PROTECTED]
WhiteCrown Networks - More Than White Hats
Web Application Security - www.whitecrown.net
*/

- Original Message -
From: John Meyer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, July 07, 2001 4:41 PM
Subject: [PHP] mysql_insert_id()


| I have been reading about this function and I have a question. The PHP
| manual warns about using it if your AUTO_INCREMENT ID field is a BIGINT.
I
| am using type INTEGER.  Am I okay with this one, or should I use the MySQL
| function.
|
| John Meyer
| [EMAIL PROTECTED]
| Programmer
|
|
| If we didn't have Microsoft, we'd have to blame ourselves for all of our
| programs crashing
|
|
| --
| PHP General Mailing List (http://www.php.net/)
| To unsubscribe, e-mail: [EMAIL PROTECTED]
| For additional commands, e-mail: [EMAIL PROTECTED]
| To contact the list administrators, e-mail: [EMAIL PROTECTED]
|
|
|


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] mysql_insert_id()

2001-07-07 Thread Don Read


On 07-Jul-01 Chris Lambert - WhiteCrown Networks wrote:
 I've used integer on many occasions with auto_increment, and have had no
 problems. mysql_insert_id() returns the unique identifyer of the last record
 inserted with mysql_query(). I'm not sure what MySQL function you're
 referencing as an alternative, but you should be fine with an
 integer/auto_increment/insert_id()...
 

PHP int values are signed integers, so when the database id  2147483647
mysql_insert_id() will return negative values.

On 32bit compile:
INT  = ok
INT UNSIGNED   will break at 50% of the domain (of valid id's)
BIGINT   ~2% 
BIGINT UNSIGNED  ~1%

I don't know if you can compile PHP for 64bit ... if you can then 
the first three should be fine.

And you can always use mysql_query(select LAST_INSERT_ID());
then treat the result as a string (which it is).

Regards,
-- 
Don Read   [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] mysql_insert_id()

2001-01-24 Thread Sam Masiello


When you are using mysql_insert_id, you don't want to pass it the result of
your previous SQL statement as in:

$result = mysql"mydb", "My SQL statement", $my_connect) ;
$last_id = mysql_insert_id($result)

Rather, you want to pass it the link identifier from your mysql_connect
like:
$result = mysql("mydb", "My SQL statement", $my_connect) ;
$last_id = mysql_insert_id($my_connect)

HTH

Sam Masiello
Systems Analyst
Chek.Com
(716) 853-1362 x289
[EMAIL PROTECTED]

 -Original Message-
From:   Boget, Chris [mailto:[EMAIL PROTECTED]]
Sent:   Wednesday, January 24, 2001 3:50 PM
To: Php (E-mail)
Subject:[PHP] mysql_insert_id()

I'm having intermittent problems with this function.
Most of the time, it returns the proper value.  However,
sometimes it doesn't return anything at all even when
the insert query executes without error and I can see the
new data in the database.  I try to get the last insert id
both by supplying the link-resource and not but still get
the same results.
When I echo out the link-resource (what mysql() returns),
all I'm gettins is a numerical one (1).  What gives?

Chris


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] mysql_insert_id()

2001-01-24 Thread Boget, Chris

 When you are using mysql_insert_id, you don't want to pass it 
 the result of your previous SQL statement as in:
 $result = mysql"mydb", "My SQL statement", $my_connect) ;
 $last_id = mysql_insert_id($result)

This is what it sounds like it's looking for in the documentation.  It
could be just how I'm reading it. :p
 
 Rather, you want to pass it the link identifier from your 
 mysql_connect like:
 $result = mysql("mydb", "My SQL statement", $my_connect) ;
 $last_id = mysql_insert_id($my_connect)

Tried this, too, with no luck. :(  I'm using mysql_pconnect() and
mysql_connect() and neither seems to help my situation.

Chris



RE: [PHP] mysql_insert_id()

2001-01-24 Thread Sam Masiello


You probably stated this in your previous post, but what is the result from
your call to mysql() ?  Is this call failing so that when you get to
mysql_insert_id(), the id doesn’t exist?

HTH

Sam Masiello
Systems Analyst
Chek.Com
(716) 853-1362 x289
[EMAIL PROTECTED]

-Original Message-
From: Boget, Chris [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 24, 2001 4:20 PM
To: 'Sam Masiello'; Php (E-mail)
Subject: RE: [PHP] mysql_insert_id()

 When you are using mysql_insert_id, you don't want to pass it
 the result of your previous SQL statement as in:
 $result = mysql"mydb", "My SQL statement", $my_connect) ;
 $last_id = mysql_insert_id($result)
This is what it sounds like it's looking for in the documentation.  It
could be just how I'm reading it. :p

 Rather, you want to pass it the link identifier from your
 mysql_connect like:
 $result = mysql("mydb", "My SQL statement", $my_connect) ;
 $last_id = mysql_insert_id($my_connect)
Tried this, too, with no luck. :(  I'm using mysql_pconnect() and
mysql_connect() and neither seems to help my situation.
Chris



RE: [PHP] mysql_insert_id()

2001-01-24 Thread Sam Masiello

Instead of checking if(!$id), perhaps you would be better off to check the
result of your query (which in this example was successful, since you got a
return from mysql() ).

Also, what is the last_insert_id() function that you are referencing in your
$insertIDQuery string?

As for things getting messed up when two queries hit the system at the same
time, you shouldn’t need to worry about that either because the two people
coming in would have different values for the $link variable and since
mysql_insert_id goes off of the link identifier of the connection (which
will be different for the two different people running queries), you should
not have a conflict.

HTH

Sam Masiello
Systems Analyst
Chek.Com
(716) 853-1362 x289
[EMAIL PROTECTED]

-Original Message-
From: Boget, Chris [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 24, 2001 4:49 PM
To: 'Sam Masiello'; Php (E-mail)
Subject: RE: [PHP] mysql_insert_id()

 You probably stated this in your previous post, but what is
 the result from your call to mysql() ?  Is this call failing so
 that when you get to mysql_insert_id(), the id doesn't exist?
I did.  It's returning a numerical one (1).
What I'm doing now is as follows.  It's getting me the value
but I'm so afraid that if 2 queries get sent almost simultaneously
it's going to screw everything up...
$link = mysql_pconnect( "localhost", "thisuser", "thatpass" );
$result = mysql( $dbname, $dbquery );
$id = mysql_insert_id( $link );
if( !$id ) { $id = mysql_insert_id(); }
if( !$id )

  $insertIDQuery = "SELECT last_insert_id()";
// get values from above query, etc., etc.
}
You get the gist of it...  I cannot believe this stupid thing won't
work otherwise...  And it's not consistent when it works and
doesn't.  Very odd.
*sigh*
Chris



RE: [PHP] mysql_insert_id()

2001-01-24 Thread Boget, Chris

 Instead of checking if(!$id), perhaps you would be better off to check the

 result of your query (which in this example was successful, since you got 
 a return from mysql() ).

I am.  I just didn't include it in my previous message as it as I was trying
to
keep extraneous code down to a minimum.  Plus, I mentioned in my initial
post that there were no errors being returned and mysql() was in fact
returning
a 1 (true) as opposed to a 0 (false) as it's result.  Both indicate that the
query
was successful.
 
 Also, what is the last_insert_id() function that you are referencing in
your 
 $insertIDQuery string?

Internal mySQL function.
 
 As for things getting messed up when two queries hit the system at the
same 
 time, you shouldn't need to worry about that either because the two people

 coming in would have different values for the $link variable and since 
 mysql_insert_id goes off of the link identifier of the connection (which
will be 
 different for the two different people running queries), you should not
have a 
 conflict.

My worry comes from the fact that I'm running an internal mySQL function
and I'm not certain that mySQL would know who was who and which insert
ID to return for 2 simultaneous queries.  But now that I think about it, I
see
that worry is misplaced.

Chris