Re: Inserting a large number of rows into mySQL

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

 



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"                                                                                                          
                      <atampone@attechco        To:       php-db@lists.php.net                                                           
                      mputer.com>               cc:                                                                                      
                                                Subject:   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


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

  Powered by Linux