Home > Archive > PHP DB > January 2007 > Re: [PHP-DB] setting SQL variable
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [PHP-DB] setting SQL variable
|
|
|
| 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");
| |
|
| 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:
>
> 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
|
|
|
|
|