Re: setting SQL variable

From: Date: Fri, 19 Jan 2007 09:58:17 +0000
Subject: Re: setting SQL variable
References: 1 2  Groups: php.db 
Request: Send a blank email to php-db+get-42961@lists.php.net to get a copy of this message
You are the right. Is possible use mysql_insert_id() and it need not stack the queries and confirm these one by one. Thanks a lot!! OKi98 wrote: > marga wrote: > >> Is not possible to use mysql_insert_id() and assing it in a php >> variable, because >> mysql_insert_id() is executed after the COMMIT, I think. > wrong, it is possible to use mysql_insert_id() during the transaction. > > the code should look like this: > > mysql_query("start transaction"); > if (mysql_query(insert into first table)) { > $id=mysql_insert_id(); > if (!mysql_query(subsequent inserts)) $error=1; > } > else $error=1; > mysql_query((isset($error)) ? "rollback" : "commit"); > -- Marga Vilalta marga at ayuken dot com Hov ghajbe'bogh ram rur pegh ghajbe'bogh jaj

« previous php.db (#42961) next »