On Fri, Sep 10, 2010 at 1:59 PM, Michael Jones <[email protected]> wrote: > We have an application that I'm converting to PHP. There are several places > that do something like this: > > $query = "START TRANSACTION;" > $query+= "INSERT INTO a (.....)" > $query+= "INSERT INTO b (...)" > $query+= "SELECT LAST_INSERT_ID() as ID" > $query+= "COMMIT" > > Since mysql_query doesn't support multiple queries per statement, what is the > best way to do this in PHP? Right now I'm using a transaction class to put > each query in an array and loop them, but efficiently handling any return > results is a bit of a puzzle.
Look into the mysqli extension. Using that you can turn off autocommit, and commit manually when you need to. But in general I prefer one query per call. This way you can check results of queries, and rollback if necessary. --lonnie _______________________________________________ UPHPU mailing list [email protected] http://uphpu.org/mailman/listinfo/uphpu IRC: #uphpu on irc.freenode.net
