Results 1 to 4 of 4

Thread: How to do multiple inserts ?

  1. #1

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17

    How to do multiple inserts ?

    Hello.

    Im wondering waht is the best / 'propper' way to do multiple inserts of data into MYSQL.

    Ive got anywhere from a few dozen - to hundreds to do.

    Is it safe to

    :-Open the MYSQLI database

    - do a foreach loop

    - insert on update etc....

    end loop

    - close the MYSQLI database.


    is it safe / propper to insert a lot of Inserts like this in one go ?




    PS - I can / know how to do this in steps - IE one insert every 5 mins until all of them done... But i'm looking for a faster way, but not sure how far i can go
    Last edited by PeterPan; 7-15-16 at 07:19 PM. Reason: Spalling mispikes

  2. #2
    target='_blank' snowmaker's Avatar
    Join Date
    Nov 2002
    Location
    West Virginia
    Posts
    3,458
    Rep Power
    22
    My database coding knowledge is nearly non existent, but in any other coding languages that I know, I would opt for some kind of loop to do that type of operation.
    -bruce /* somdcomputerguy */
    'If you change the way you look at things, the things you look at change.'

  3. #3

    Join Date
    Sep 2002
    Location
    Auckland
    Posts
    1,356
    Rep Power
    17
    The process is easy enough to do _ The question i'm asking is - Is it safe to do 10 at a time? 100 at a time ? 1000 at a a time ? 10,000 at a time ?

    $sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
    VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

    (do / process SQL)

    $sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
    VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

    (do / process SQL)

    $sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
    VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

    (do / process SQL)

    $sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
    VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

    (do / process SQL)

    $sql="INSERT INTO `nwcategories` (`CatLatest`, `CatUNIQUE`, `CatReference`, `CatCategory`)
    VALUES(NOW(), \"$unique\", \"$ID\", \"$ax\") ON DUPLICATE KEY UPDATE `CatLatest`=NOW()";

    (do / process SQL)

    Close MYSQL... (in a loop)

  4. #4
    target='_blank' snowmaker's Avatar
    Join Date
    Nov 2002
    Location
    West Virginia
    Posts
    3,458
    Rep Power
    22
    Well I couldn't really say if it's safe or not safe. I know that loops are a lot easier to write and manage.. I'm sure that someone with more MySQL coding experience could tell you, perhaps going to a database forum would get you a quicker answer..
    -bruce /* somdcomputerguy */
    'If you change the way you look at things, the things you look at change.'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •