0

I have a php loop that executes a mySQL query for each cycle of the loop. Right now my loop is hitting a mySql error and stopping. How do I set it up so when it hits a mySql error it just stops what it's doing and moves on to the next loop?

I have added the code below. Please keep in mind I am not trying to solve the SQL error but rather tell the php loop to skip over it.

   foreach ($queryData as $value) { 
       mysql_query(" PREPARE stmt FROM 'INSERT INTO `table_name`( `column_name`) VALUES   ('value'  )'EXECUTE stmt1"
                   )or die("die message");
                                  }
3
  • 1
    Show us the code that generates the error. Why don't you just fix the error? Commented Apr 25, 2013 at 1:38
  • You could throw an exception Commented Apr 25, 2013 at 1:40
  • You'd get more productive help if you actually shared the code and query in question. Commented Apr 25, 2013 at 1:42

1 Answer 1

1

If you don't want to halt upon execution, just omit the die.

$res = mysql_query($sql);
if ($res) {
 /* do stuff with the query results */
} else {
  /* output an error if desired... or don't */
  echo 'There was a database error: '.mysql_error();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.