Is there a way unset $rsnew["id"] where id is auto increment field?

My setup:

  • table: table
  • field: table.id set as auto-increment

Row_Inserting()
$sql = “call someproc(…)”; // this procedure insert many rows into table (and another tables)
Execute($sql);

Since I can’t unset($rsnew[“id”]) and phpm is firing
INSERT INTO table() value();

Then for that empty row I have to
Row_Inserted()
$sql = “delete from table where id=”.$rsnew[“id”];
Execute($sql);

My question,

  1. Is there a way to unset($rsnew[“id”]), of which id is auto-increment ?
  2. Or, is there a way so that phpm not firing “INSERT INTO table() value();” ?

If you mean resetting the next value for auto-increment field, it depends on what database type you are using. For example, for MySQL, google for “reset auto_increment mysql”.

The issue is not with auto_increment value.

Same case, different setup:

  • table: table is UNION of 2 base tables namely tableA and tableB. Both have PK auto_increment.
  • field: field value decide which PK-id belong to which table.

Like my previous case, I have:
Row_Inserting()
if ($rsnew[“field”] === “A value”) {
// do something (like calling stored procedure).
} elseif ($rsnew[“field”] === “B value”) {
// do something else
};
Obviously I don’t need “INSERT INTO …” to any tables.

That means I don’t need this:
Row_Inserting()
if ($rsnew[“field”] === “A value”) $this->UpdateTable = “tableA
elseif ($rsnew[“field”] === “B value”) $this->UpdateTable = “tableB” ;

So then I don’t need this either:
Row_Inserted()
if ($rsnew[“field”] === “A value”) Execute(“delete from tableA…”);
elseif ($rsnew[“field”] === “B value”) Execute(“delete from tableB…”);

Instead, to avoid those confusing codes, I create a dummy table dummy with only a PK-field and nothing else.

So now,
Row_Inserting()
if ($rsnew[“field”] === “A value”) {
// do something (like calling stored procedure, etc).
} elseif ($rsnew[“field”] === “B value”) {
// do something else
};
$this->UpdateTable = “dummy”;

Then,
Row_Inserted()
Execute(“delete from dummy …”); // I can fire this or not, whatever

This “dummy approach” also applicable to my previous case.
Bottom line: It’s not auto_increment issue but rather flexibility issue.

Use Row Inserted event with ‘" . $rsnew[“id”] . "’

NOT Row Inserting event

you need auto_increment Done after thats use its