[PHP-DB] Inserting a large number of rows into mySQL

2003-07-18 Thread Anthony
I'm writing an app where I must insert a large number of rows into a mySQL
database individually.  All the rows are related to each other, so I need to
ensure that integrity is maintained.  In the event that one of the inserts
fails, I need to be able to roll back all the prior inserts.  What is the
best way to insert the rows individually, yet still have this ability?  The
rows will be inserted by looping though an array in PHP.  Thanks.

- Anthony



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



Re: [PHP-DB] Inserting a large number of rows into mySQL

2003-07-18 Thread jeffrey_n_Dyke

If you have the standard table type installed
As you loop though though the arrays in PHP get ahold of the last ID
inserted via mysql_insert_id() and add it to an $inserted_array variable
and then at each insert check that the last insert was successful, and if
not send your db a bunch of deletes based on the keys in $inserted_array.

but if you are running a InnoDB or BDB table then you can set AUTOCOMMIT =
0 and use the Begin/Commit/Rollback syntax to accomplish this.

hth...i'm sure there are 10 more ways to do this
jeff




   
  
  Anthony
  
  [EMAIL PROTECTED]To:   [EMAIL PROTECTED]
   
  mputer.com   cc:
  
Subject:  [PHP-DB] Inserting a large 
number of rows into mySQL   
  07/18/2003 10:04 
  
  AM   
  
   
  
   
  




I'm writing an app where I must insert a large number of rows into a mySQL
database individually.  All the rows are related to each other, so I need
to
ensure that integrity is maintained.  In the event that one of the inserts
fails, I need to be able to roll back all the prior inserts.  What is the
best way to insert the rows individually, yet still have this ability?  The
rows will be inserted by looping though an array in PHP.  Thanks.

- Anthony



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






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