Re: Multiple Inserts with mySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Try this:

$stack is an array of hashes:

$stack[0] = array(0=>tablename, 1=>insertid());

For each insert you do, push an anonymous array on $stack which includes
the tablename and insertid of the insert.

Then as you continue your inserts, if any of them fail, call a function
which takes that array $stack, and iterate through it, deleting the rows
you just inserted. (see mysql_insert_id() function to get the insert ID)

If none of them do fail, then you are in the clear.  Either unset $stack or
ignore it.

Peter

On Wed, 13 Nov 2002, Anthony wrote:

> I have to drop a lot of data into mySQL from PHP.  It will go into quite
> a few different tables.  How can I maintain integrity of the entire
> insert?  I need to do about a dozen inserts on four tables and I need to
> insure that all the inserts are successful or that none of them get
> done.  I'm sort of new at this, so please help me out.  Thanks.
>
> - Anthony
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

---------------------------------------------------------------------------
Peter Beckman            Systems Engineer, Fairfax Cable Access Corporation
beckman@purplecow.com                             http://www.purplecow.com/
---------------------------------------------------------------------------


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux