Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Streda, 11. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Insert trigger and LAST_INSERT_ID

phpMyEdit Configuration     Insert trigger and LAST_INSERT_ID
Odoslať novú tému   Odpovedať na tému    
 
KarelB     Založený: 01.06.2007   Príspevky: 24  
Príspevok Zaslal: 2008-04-09 20:29
Návrat hore  Odpovedať s citátom     

All,

I want to run a script after I copied a record from my table. So I created an insert.after trigger and I want to capture the id of the newly created record as well as the old id where it was copied from. (id is an auto-increment field)

The old id I can get but the id of the newly created record gives me headaches. In a previous topic from 2004 it was suggested that you have to capture the new id yourself.

But both mysql_insert_id() or SELECT LAST_INSERT_ID() return 0. Occording to the MYSQL manual this indicates that the last insert failed, but the new record is created.

I am the only user of the database and of course there are no inserts or updates in the trigger.

What am I missing here. Any body any ideas?

Thanks in advance,

Karel

 
Icehawg     Založený: 09.04.2008   Príspevky: 20  
Príspevok Zaslal: 2008-04-10 13:55
Návrat hore  Odpovedať s citátom     

There is a function in the list called sql_insert_id() which returns the mysql_insert_id function (which, in turn, is a call to get the ID generated from the previous INSERT operation) .

I haven't tried it yet but I would wager that an "insert.after" trigger to $this->sql_insert_id would return the value you are seeking.

 
Icehawg     Založený: 09.04.2008   Príspevky: 20  
Príspevok Zaslal: 2008-04-10 14:38
Návrat hore  Odpovedať s citátom     

I also found this forum thread that might be of more use :

http://opensource.platon.sk/forum/projects/viewtopic.php?t=7887&highlight=trigger

 
Icehawg     Založený: 09.04.2008   Príspevky: 20  
Príspevok Zaslal: 2008-04-11 22:04
Návrat hore  Odpovedať s citátom     

If it were possible I would kiss you full on the mouth for pointing me to this class script. :) I have been spending years using a self-made ugly kludgy thing that did a portion of what that fantastic dBug does.

 
Icehawg     Založený: 09.04.2008   Príspevky: 20  
Príspevok Zaslal: 2008-04-15 12:18
Návrat hore  Odpovedať s citátom     

doug Napísal:
Hah! Please don't! The username "Icehawg" somehow conveys to me that you are neither female, nor as beautiful as a Hollywood actress!


My mom says I am the handsomest boy though! :) But my wife would probably object ...and now I am creeping myself out so I shall stop.

doug Napísal:
Aside from the dBug.php script, my favorite debug code is this:

Kód:
$print_r_text =
  preg_replace('/\n/s', "\r\n", print_r($_POST, true));

echo !stristr($print_r_text, ']')
  ? ''
    : "\n".'<pre>'.htmlspecialchars($print_r_text).'</pre>';


Any array can be substituted for $_POST.


Ya I was doing something similar to that but depending on the array/contents, I would get some fugly results. dBug for the win!

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov