phpbar.de logo

Mailinglisten-Archive

[php] 1/2 OT: Satznummern

[php] 1/2 OT: Satznummern

Egon Schmid eschmid_(at)_s.netic.de
Sun, 14 Nov 1999 13:35:52 +0100


Hannes Streicher wrote:

> ich lasse mich hier jedoch gerne von den guru's korrigiern wenn das da oben
> falsch ist.

Ein Guru (Paul DuBois) formulierte es so:

int
mysql_insert_id ([int link_id]);
Returns the AUTO_INCREMENT value generated by the most recently executed
query on the given connection. Returns zero if no such value has been
generated during the life of the connection. Generally, you should call
mysql_insert_id() immediately after a query that you expect to generate
a new
value; if any other query intervenes between that query and the point at
which you want to use the value, the value of mysql_insert_id() may be
reset
to zero by the intervening query.
Note that the behavior of mysql_insert_id() differs from that of the SQL
function LAST_INSERT_ID(). mysql_insert_id() is maintained
in the client and is set for each query. The value of LAST_INSERT_ID()
is maintained in the server and persists from query to query.
The values returned by mysql_insert_id() are connection-specific and are
not affected by AUTO_INCREMENT activity on other connections.

   <?php
       $link = mysql_pconnect ("pit-viper.snake.net", "paul", "secret")
           or die ("Could not connect");
       mysql_select_db ("samp_db")
           or die ("Could not select database");
       $query = "INSERT INTO member (last_name,first_name,expiration)"
           . " VALUES('Brown','Marcia','2002-6-3')";
       $result = mysql_query ($query)
           or die ("Query failed");
       printf ("membership number for new member: %d\n",
mysql_insert_id());
   ?>

So oder so ähnlich wird es auch demnächst in einer der nächsten Auflage
des Handbuches erscheinen. Der User wird dann wahrscheinlich Marliesle
heissen.

-Egon


php::bar PHP Wiki   -   Listenarchive