Submit Text File Contents To Database[Script Need Help]

Discussion in 'PHP' started by poblo10, Oct 26, 2010.

  1. #1
    So what I'm trying to do is insert text file contents from a text file into a database.

    And this script works, but only for small amounts of words in the text file

    I'm trying to submit anywhere from 1,000's-millions of words at a time from a text file.

    When I try the larger text files it just doesn't submit them.

    So if someone could alter this script to be able to submit that many or give/point me in the direction of a different script.


    Current insert text file contents to mysql database script.
    <?php
    include('./inc/connect.php'); //My connect script. 
    // Build the lines array, thus $lines[0] will be the first and etc.
    $lines = array_map ('trim', file ("names.txt", FILE_SKIP_EMPTY_LINES));
    $sql = "INSERT INTO words (word) VALUES ";
    foreach ($lines as $index => $curLine)
    {
      $sql .= "('$curLine')";
      
      // count () returns the number of lines, but it isn't zero-based, so we add 1 to the line number to make sure it isn't the last element to avoid the trailing comma
      if (count ($lines) != ($index + 1))
      {
        $sql .= ", ";
      }
    }
    
    // And query it
    mysql_query ($sql);
    
    
    ?>
    PHP:
     
    poblo10, Oct 26, 2010 IP