SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    my title of the thread may be a little misleading but I'd like to know if it is anyway possible to use one insert function to insert allot or records.

    Even for just 2 records would help because then I could change it to 20,000 if it were possible

    So does anyone know if this is remotely possible?

    Thanks
    peter

  2. #2
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    It is a good idea to use as few inserts as possible. One way to cut down on your inserts is to build a string with your data dynamically:
    Code:
    for ($x=0; $x<$datasize; $x++)
    {
       $values .= $data . ",";
    }
    
    //remove last comma:
    $values = substr($values, -1);
    
    $sql = "INSERT INTO yourtable (fieldname) VALUES ($values)";

  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If datasize = 15000 would is create 15000 rows or 1?

    -Peter

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by MattR
    <font face="verdana, arial, helvetica" size="2" class="mfont">No.</font>
    i feel weird contradicting the database "God" but.. this works for me:


    $query = "INSERT INTO settings (settings,value,category) VALUES
    ('allow_registration','Y','Settings'),
    ('email_registration','Y','Email'),
    ('email_validation','Y','Email')"


    sort of thing.

  6. #6
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thankyou, so now I can do a 15,000 insert without worrying too much about the server, instead of doing 15000 insert commands.

    Thank you

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, it is what i use although 15,000 inserts... wow

  8. #8
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its a 2 column insert , ID and Text, text is a 200 varchar. So its not that big, but I wouldn't want to crash the server on a shared account.

    Pete

  9. #9
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you were only doing it once, i seriously doubt it would crash the server but better be safe than sorry. A 15,000 insert query might take a while to complete.. no idea how long though.

  10. #10
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by padders
    i feel weird contradicting the database "God" but.. this works for me:
    $query = "INSERT INTO settings (settings,value,category) VALUES
    ('allow_registration','Y','Settings'),
    ('email_registration','Y','Email'),
    ('email_validation','Y','Email')"
    sort of thing.</font>
    LOL -- that may be true in MySQL, but is NOT in the ANSI spec (more importantly MySQL specific ) and therefore is not something I learn. So there.
    Last edited by MattR; Apr 22, 2001 at 20:54.


Bookmarks

Posting Permissions

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