1

For some reason, i want to delete some of records in my table using php mysql query function. Here's what i've write

$sql = "delete from progress where first_date='2010-01-01' and last_date='2010-01-31';
delete from progress where first_date='2010-02-01' and last_date='2010-02-28';
delete from progress where first_date='2010-03-01' and last_date='2010-02-31';
delete from progress where first_date='2010-04-01' and last_date='2010-02-30';
delete from progress where first_date='2010-05-01' and last_date='2010-02-31';";

if(!mysql_query($sql)) echo "Error deleting records";

Thats exactly what i get, "Error deleting records". However when itrace it using mysql_error() , its no use after all. Anyone know how to handle this? Thank's before

1
  • Change your final echo there to echo 'Error deleting records: ', mysql_error();, which will spit out the exact error that occured. Just saying "something happened" is of no use. Commented Jul 2, 2010 at 14:54

4 Answers 4

6

mysql_query() can't execute multiple statements for security reasons.

use mysqli_multi_query() or call mysql_query() many times.

Sign up to request clarification or add additional context in comments.

1 Comment

yes i did using mysqli_multi_query but once i got error : 'command out of sync, you can't command now' or smiliar
3

You cannot send more than one SQL query at a time when using mysql_query(). That is why it's failing and returning false.

2 Comments

that's what i've tought before. It's strange beacuse when i use phpmyadmin everithing looks fine
I think it's because phpMyAdmin parses your SQL, splits statements by the given delimiter and runs mysql_query() once for each separate statement.
0

you can either create different variables for each query and then call the mysql_query for each variable created. i did it this way when i wanted to execute two queries to select and update at once.

Comments

0

Why not combine all queries into one?

$sql = "DELETE FROM progress WHERE (first_date='2010-01-01' AND last_date='2010-01-31') OR (first_date='2010-02-01' AND last_date='2010-02-28') OR (first_date='2010-03-01' AND last_date='2010-02-31') OR (first_date='2010-04-01' AND last_date='2010-02-30') OR (first_date='2010-05-01' AND last_date='2010-02-31')";

1 Comment

I will use PDO nowadays, not mysql_query. But your code might worked back then.

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.