Re: Multiple Inserts with mySQL

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

 



hmm, I guess that would work.  There is no way to have mySQL check for 
integrity for me is there?  I read in a SQL book a while ago about 
wrapping multiple inserts in a select statement, that way if any part of 
the statement failed the whole thing would be rolled back.  From my 
research though, it doesn't look like mySQL supports this.  Am I right 
here?  So far it looks like your idea could be the most reliable 
suggestions I've gotten, so I'll start working on that for now.  Thanks.

- Anthony

Peter Beckman wrote:
> 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