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
mysql_query() can't execute multiple statements for security reasons.
use mysqli_multi_query() or call mysql_query() many times.
You cannot send more than one SQL query at a time when using mysql_query()
. That is why it's failing and returning false.
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.
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')";
精彩评论