Posted By

arcturus on 08/19/06


Tagged

mysql php


Versions (?)

Select index from last inserted item.


 / Published in: PHP
 

Select the last autoincrement index from the last inserted item in a table.

  1. //Bloqueamos la tabla
  2. mysql_query("LOCK TABLES myTable WRITE");
  3. //Hacemos el insert
  4. mysql_query("INSERT INTO myTable ......");
  5. //Obtenemos el id del proyecto
  6. $result_id=mysql_query("SELECT LAST_INSERT_ID()");
  7. define('MY_ID',mysql_fetch_row($result_id));
  8. //Desbloqueamos
  9. mysql_query("UNLOCK TABLES");

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Jameson on August 21, 2006

The same much quicker and cleaner: 1. mysqlquery("INSERT INTO myTable ......"); 2. define('MYID',mysqlinsertid());

You need to login to post a comment.