Getting value of auto-incremented key on Row_Inserting

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
kartuli
User
Posts: 20

Getting value of auto-incremented key on Row_Inserting

Post by kartuli »

When I'm inserting a row, I want to get the value of the primary key (called "thekey") from the row - I need to know it so I can update another field in the row with a combination of the value of "thekey" and some other stuff.

But $rsnew["thekey"] is empty in Row_Inserting, and by the time we get to Row_Inserted, well,... the row's inserted.

How can I grab the auto-incremented primary key on an insertion, so I can use it as part of the contents of another field in that same row?

Thanks for any suggestions.


scs
User
Posts: 694

Post by scs »

Try this,

$GLOBALS["conn"]->Insert_ID()


danielc
User
Posts: 1601

Post by danielc »

Key value will get after inserted. However, you can modify your record by update the database in Row_Inserted server event:
$new = $rsnew["ID"] . $rsnew["yourfield"]; // assume you want to concat ID field and other field
ew_Execute("UPDATE <yourtable> SET <yourfield> = '" . ew_AdjustSql($new) . "' WHERE <ID> = " . $rsnew["ID"]); // assume ID is your ID field


Post Reply