<p>I always hear that using "lastInsertId" (or mysql_insert_id() if you're not using PDO) is evil. In case of triggers it obviously is, because it could return something that's totally not the last ID that your INSERT created.</p>

<pre><code>$DB-&gt;exec("INSERT INTO example (column1) VALUES ('test')");
// Usually returns your newly created ID.
// However when a TRIGGER inserts into another table with auto-increment:
// -&gt; Returns newly created ID of trigger's INSERT
$id = $DB-&gt;lastInsertId();
</code></pre>

<p>What's the alternative?</p>

It's not sophisticated and it's not efficient, but if the data you've inserted include unique fields, then a SELECT can obviously yield what you're after.
For example:
```
```
INSERT INTO example (column1) VALUES ('test');
SELECT id FROM example WHERE column1 = 'test';
```
```