Thanks to you and all the others who helped me out with this. I *am* using
MyISAM tables, and everything is working the way I want it to. This is every
bit as fast as the last_insert_id, with the added benefit that it is
accurate no matter which thread I hit 8-). Yes, I am using pconnects, and my
I have a hit counter script that logs all its hits in one table, one row per
hit.
Currently, I have been counting the rows in PHP in order to get the value of
the last hit_id in the database like this:
$sql4 = SELECT hits.hit_id from hits;
$result = mysql_query ($sql4, $connection)
or
LAST_INSERT_ID is the value of the auto increment field in the table that was last
inserted into. You probably want:
$sql4 = SELECT MAX(hits.hit_id) as max_hit_id
as pixels
from hits;;
--jfarr
-
Before posting, please
Read the manual again on last_insert_id(). That function only gives you the
unique id of the last insert *for that thread* If you connect, don't do any
inserts, and select last_insert_id, there is no guarentee what you will get.
If you are trying to find the number of rows, it would be much
Currently, I have been counting the rows in PHP in order to get the value of
the last hit_id in the database like this:
You have mysql_insert_id() in php to get the last autoincrement
value. This is _not_necessarily_ the same as the number of rows.
It's staggering the difference in speed.
$sql4 = SELECT hits.hit_id as pixels from hits
WHERE hit_id=LAST_INSERT_ID();;
$result = mysql_query ($sql4, $connection)
or die(error # . mysql_errno() . : . mysql_error());
$row = mysql_fetch_object($result);
$pixels = number_format($row-pixels);
It's staggering the difference in
Adding, For that thread.
selecting LAST_INSERT_ID() for a pseudo-foreign keys system is reliable.
The only case I can possibly think of, Of this being a problem is when
you're dealing with a persistent connection to the database which is
shared among multiple applications.
Jonothan Farr
That I'm trying to do here is get the VALUE of hit_id from the last row of
hits. It is an auto-increment number, but it is much higher than the count
of the rows, because people go through and delete their hits from time to
time. Am I correct in assuming that auto-numbers are never re-used?
Yes, you are correct in assuming that, but ONLY if you use MyISAM tables.
BDB and ISAM tables reuse number, kind of.
Ex:
1
2
3
4
5
If you delete 5, the next record you insert will have an ID of 5. If you
delete 4 instead of 5, the next one inserted will have an ID of 6. So, BDB
and ISAM
This is precisely what I did, only I left out the 'as max_hit_id' part, and
jumped right to pixels. Works quickly and neatly. Thanks very much.
Walter
On 7/20/01 6:35 PM, Jonothan Farr [EMAIL PROTECTED] wrote:
LAST_INSERT_ID is the value of the auto increment field in the table that was
last
10 matches
Mail list logo