How to skip error msges ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shalini Bhalla
    New Member
    • Dec 2007
    • 190

    How to skip error msges ?

    i have written a script that will insert data into database after readingfrom csv file.But i get a problem when if due to some reason insert statement gets error .The whole uploading process stops.

    What i want is that :

    When ever insert statement gets error it should't stop,Should continue jumping on next record. and at the end it should me give msg that these many records are not being inserted due to this reason.

    how to catch exceptions in php+mysql ?


    Pls help
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Ok, loop through your queries, then you and IF check to see if the query was successful (queries return TRUE if are successful, else FALSE). Something like the below (pseudo).

    Code:
    $badQueries = array();
    
    foreach($queries as $x => $query)
    {
        if ( ! $query )
        {
            // query didn't work :(
            $badQueries[] "$x didn't execute - " . mysql_error();
        }
    }

    Comment

    • Shalini Bhalla
      New Member
      • Dec 2007
      • 190

      #3
      Trapping My Sql Errors ....

      i have a csv file which i need to upload in database using insert statement.

      now the thing is that if by chance there is any problem in any insert statement , it gives me error message and stops the whole process.

      i don't want to stop the whole process . i want that it should continue and should stop at the eof telling me how many queries were successfull and how many were not.

      Is it possible ?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Shalini Bhalla, it is against the forum guidelines to doulbe post a question. This is your first official warning as you have been here long enough to know the guidelines.

        Read the forum guidelines now, to avoid any further warnings.

        Moderator.

        Comment

        • Shalini Bhalla
          New Member
          • Dec 2007
          • 190

          #5
          but i did't get the ans sir ........sorry for that will not happen again...

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            My first post in this thread explains an easy way to do it.

            Comment

            • mwasif
              Recognized Expert Contributor
              • Jul 2006
              • 802

              #7
              Shalini,

              What you have made so far?

              Comment

              • Shalini Bhalla
                New Member
                • Dec 2007
                • 190

                #8
                What i did ...

                Actually my requirement was to insert data from one csv file to a database and after printing i wanted my script to print how many inserted , how many were duplicate hence skiped and how many were containing some empty fields hence skiped.

                I was stucking at the point where due to some reason insert statement get error and stops the whole uploading,

                I wanted to do exception handling for that

                But now i have taken this in consideration that my data should not contain any special character , mainly "." or " ' " or ' " ' so that insert statement shouldn't stop . And done it for the time being .....

                Now its checking empty fields and duplicate which are not entered in database and counting for empty , duplicate and insert data and printing it .....

                But still i want to learn exception handling for it ... any good tutorial site you suggest ....

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Exception handling: google is your friend.

                  To escape any harmful characters in your query, use mysql_real_esca pe_string() on your string.

                  Comment

                  Working...