Getting name of table INSERT queries

Hey, I’m looking for a way to get the name of the table an INSERT-query worked on. I got the query’s result (from mysql_query) and the string. I concidered doing string searches and narrowing it down between either “INSERT INTO " and " VALUES” or " (“, but that’ll go horribly wrong if the table name has " VALUES” in it, or if it’s got a " (" in it. They’re all possible (I tested that), which leaves string searching out as an option. Anybody here know how to get the table name then?

Why would you ever run a query that your own program didn’t produce?

Look for the word after INSERT INTO (delineated by spaces and potentially backticks).

I’m trying to make an object that handles queries, and thought it’d be useful to allow it to hand back the inserted record (or updated record in case of updates).

The problem with looking for the word after INSERT INTO is that a table can just as well be called “My Superduper Table (yes I know it is seriously cool)”. Because of that, it’s hard to define where exactly a table name stops.

It’s not; it would have to be enclosed in backticks which tells you exactly where it starts and stops. If there are no backticks, then you only need to look for spaces.

INSERT INTO My Superduper Table (yes I know it is seriously cool) VALUES (…)

is not a valid query; MySQL would barf after the word My

Ohhhh, right. Thanks:D

Keep in mind that the following are also valid (in MySQL anyway)

INSERT DELAYED INTO `table_name` ...
INSERT INTO database.my_table ....

Might be more trouble than it’s worth.