How to query new records?

I would not expect any unless maybe it’s trying to use a persistent connection?

Typically the problem is that other inserts are being done before last insert id is called.

By that, you mean other inserts in the same script, right?

Yep. If your cron has kicked off say 5 instances then they should all be completely independent as far as the last inserted id is concerned. It’s only within a script that things can mess up.

From what I remember about that particular script, each SQL query was wrapped in its own PHP function. The sequence of events from insert to calling lastInsertId() in one function occurs before another function gets called. There’s no possibility I can see of another insert occurring in the same script before lastInsertId() is called.

That project is over and done now, at any rate. I may dig up the script and try to find the bug, but I doubt it.

mysql addconnection()

help you to create connection.

Got a link to that in the PHP documentation? Sounds very interesting but I can’t find it.

It does sound interesting, but we’re stuck with a legacy Zend-based framework.