how to get from database the last inset id before insert
<p>How to select the last insert id from database table</p>

<p>i need to get the last insert id from database </p>

<p>i try the <code>last_insert_id()</code> function but this doesn't work for me because i want to get this id before i do an insert query and when i get this id i do an insert query</p>

<p>i try to use <code>max</code> for the id but this have a problem that if i have a deleted 
id it will not be taken </p>

<blockquote>
  <p>example if i have id 10 deleted than the max id will be 9 but the auto
  increment will be 11</p>
</blockquote>

<p>than i want to have the new id that will be added by the auto increment </p>

<blockquote>
  <p>example:i have an id 10 deleted i want to take than next id it will be
  11</p>
</blockquote>