SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Serial Site Creator ToddW's Avatar
    Join Date
    Feb 2004
    Posts
    791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL Insert Error - Continue?

    Hey guys, I`m wondering if it's possible or feasable to continue entering rows of data if one row causes an error.

    For instance if I am trying to enter 5k rows of data, and for some reason one raw causes an error is it possible to tell the script to STOP goto next line and continue? And of course write the errored row to an error log??

    Or would it best to just say "error importing on line #" ?

    The script will be used to import ~3-5k rows per-day so it's not a one time thing..

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding a @ in front of the mysql_query() function.

  3. #3
    Serial Site Creator ToddW's Avatar
    Join Date
    Feb 2004
    Posts
    791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I should mention the data is coming from an Array from phps' fgetcsv function.

    I have inserted over 50k rows at once with no errors either but I want to be prepared.. Right now I have it halting, and telling me which line caused the error. However if possible I`d like it to skip to the next item in the array and write the "errored" data to an error log.

    Thanks again.

  4. #4
    Serial Site Creator ToddW's Avatar
    Join Date
    Feb 2004
    Posts
    791
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by WhSox21
    Try adding a @ in front of the mysql_query() function.
    I`m not sure but wont that just surpress the error message, and the error still occurs.. meaning it could technicaly halt the script in its' tracks. ???

    I would of course use @ however I want to continue with the import by going to the next row... And recording the mysql errors and row error occured and row value to an error log.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding php's function: addslashes() to the area where it is coming with an error. Most likely you're getting some type of error because of that.

  6. #6
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your data is comma (and whatever) separated, it would be probably cleaner and faster to use LOAD DATA instead of bunch of INSERTS.


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
  •